I have a DTO which is an input param for the API's POST endpoint.
The DTO has got data annotations and validation happens automatically. Following is an example:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-f14406a8950b1005234cc79298a79586-77222ebbed97e453-00",
"errors": {
"Email": [
"The Email field is not a valid e-mail address."
]
}
}
However, when I want to raise 400 response from the controller, using either of the following:
return BadRequest("some message")
This returns some message
Where as this: return BadRequest(new { message = "some message"}); returns:
{
"message": "some message"
}
How to ensure that the same format is used throughout? Is there any in-built way to standardize.