Is it feasible to customize the error response generated by class-validator in NestJs?
The default error message structure in NestJS looks like this:
{
"statusCode": 400,
"error": "Bad Request",
"message": [
{
"target": {},
"property": "username",
"children": [],
"constraints": {
"maxLength": "username must be shorter than or equal to 20 characters",
"minLength": "username must be longer than or equal to 4 characters",
"isString": "username must be a string"
}
},
]
}
However, the external service interacting with my API requires a format closer to:
{
"status": 400,
"message": "Bad Request",
"success": false,
"meta": {
"details": {
"maxLength": "username must be shorter than or equal to 20 characters",
"minLength": "username must be longer than or equal to 4 characters",
"isString": "username must be a string"
}
}
}