I have a controller in my ASP.NET Core 3.1 app that returns BadRequest()
in one of the cases.
By default it produces the json response:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "Bad Request",
"status": 400,
"traceId": "|492dbc28-4cf485d536d40917."
}
Which is awesome, but I'd like to add a detail
string value with a specific message.
When I return BadRequest("msg")
, the response is a plain text msg
.
When I do it this way BadRequest(new { Detail = "msg" })
, the response is a json:
{
"detail": "msg"
}
Which is better, but I'd like to preserve the original json data as well.
My goal is to return this kind of response:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "Bad Request",
"detail": "msg",
"status": 400,
"traceId": "|492dbc28-4cf485d536d40917."
}
Is there a way to accomplish this?