Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@exanest/better-validation-pipe

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@exanest/better-validation-pipe

This pipe extends Nest's [built-in validation pipe](https://docs.nestjs.com/techniques/validation#using-the-built-in-validationpipe) and makes it a bit more descriptive.

  • 0.1.3
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Better Validation Pipe

This pipe extends Nest's built-in validation pipe and makes it a bit more descriptive.

Introduction

The default validation pipe is great, but error it returns is just an array of errors:

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": ["email must be an email", "phone cannot be empty"]
}

This package changes the message to be an object with field names as keys:

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": {
    "email": ["email must be an email"],
    "phone": ["phone cannot be empty"]
  }
}

So then, on your frontend, you can show each error next to its relavant field, instead of showing all of them at the end of your form

Installation

On Yarn:

yarn add @exanest/better-validation-pipe

On NPM:

npm install @exanest/better-validation-pipe

Motivation

This behavior is achievable by passing a custom exceptionFactory to the original pipe, but I found myself writing the same exception factory for each one of my projects, so I made this small package.

Inspiration

This is the same way Laravel returns errors; as an object that contains arrays of errors (strings).

FAQs

Package last updated on 12 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc