You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, NestJS follows the error response structure below for validation errors:
{
"message": [
"userEmail must be an email"
],
"error": "Bad Request",
"statusCode": 400
}
In this structure, the message field contains specific error details, and the error field provides a generalized HTTP status code error message.
However, after integrating I18nValidationExceptionFilter for enabling DTO validation, the response structure changes to:
{
"statusCode": 400,
"message": "Bad Request",
"errors": [
"userEmail must be an email"
]
}
In the updated structure:
The message field, which should indicate the actual reason for the error, now shows a generalized HTTP status code error message.
The error field has been renamed to errors and purpose of error was not follows nestJs default error res.
This change in the response structure causes inconsistencies, as validation errors now follow a different format compared to other exceptions.
Request:
To maintain consistency in error response structures, could the response format be standardized, particularly ensuring that the message, error field consistently provides the specific reason for the error across all exception types?
Describe the bug
By default, NestJS follows the error response structure below for validation errors:
{
"message": [
"userEmail must be an email"
],
"error": "Bad Request",
"statusCode": 400
}
In this structure, the message field contains specific error details, and the error field provides a generalized HTTP status code error message.
However, after integrating I18nValidationExceptionFilter for enabling DTO validation, the response structure changes to:
{
"statusCode": 400,
"message": "Bad Request",
"errors": [
"userEmail must be an email"
]
}
In the updated structure:
The message field, which should indicate the actual reason for the error, now shows a generalized HTTP status code error message.
The error field has been renamed to errors and purpose of error was not follows nestJs default error res.
This change in the response structure causes inconsistencies, as validation errors now follow a different format compared to other exceptions.
Request:
To maintain consistency in error response structures, could the response format be standardized, particularly ensuring that the message, error field consistently provides the specific reason for the error across all exception types?
main.ts:
app.useGlobalPipes(new I18nValidationPipe({ whitelist: true }));
app.useGlobalFilters(new I18nValidationExceptionFilter({}));
user.entity.ts
@isemail(
{},
{
message: i18nValidationMessage(
'validation.INVALID_EMAIL',
),
},
)
userEmail: string;
Reproduction
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: