I am using class-validator in NestJS to create valdations like this:
export class LoginDTO {
@IsEmail()
@MinLength(4)
email: string;
@IsNotEmpty()
@MinLength(4)
password: string;
}
It works, but not as expected. The returned object looks like this :
{
"statusCode": 400,
"message": [
"email must be longer than or equal to 4 characters",
"email must be an email"
],
"error": "Bad Request"
}
While i want it to contain all the information like this :
{
"statusCode": 400,
[{
target: /* post object */,
property: "title",
value: "Hello",
constraints: {
length: "$property must be longer than or equal to 10 characters"
}]
"error": "Bad Request"
}
How to do to return all the missing properties ?
This was a breaking change in Nestv7. From the migration guide when using the ValidationPipe you can pass an exceptionFactory property like this
exceptionFactory: (errors) => new BadRequestException(errors),
and it should give you what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With