I am new to .Net 6 Web API, and I am trying to learn. I build a dummy app that you can add and retrieve city. Currently, when I send an id to find a city. If the idea does not exist I return the NotFound(), and the response looks like
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.4",
"title": "Not Found",
"status": 404,
"traceId": "00-48573a8a76307babb35bad289828ef16-0bdc7cccfcfee10c-00"
}
But when I sent extra information to the NotFound($"City with Id={id} is not found")
I get the response like a string.
Is there a way to use NotFound(pass data)
and get a response like similar to original response plus a property "Error": "city with id = 3 is not found"
{
"Error": "city with id = 3 is not found"
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.4",
"title": "Not Found",
"status": 404,
"traceId": "00-48573a8a76307babb35bad289828ef16-0bdc7cccfcfee10c-00"
}
Thank you for your help.