Error handling, when we are talking about APIs, means returning information that can possiblybe consumed by a non-human endpoint in the event of an error that can provide useful information. The W3C (which is World Wide Web Consortium) this, on RFC 7807 (https://tools.ietf.org/html/rfc7807), as "a way to carry machine-readable details of errors in an HTTP response
".
The idea here is that when an error occurs, we gather all the useful information and return a response that describes what happened with the appropriate level of detail.
One way to intercept any exceptions that occur on a web request is through an exception handler—a middleware that is added through a call to UseExceptionHandler. Let's look at an example:
app.UseExceptionHandler(errorApp =>
{
errorApp.Run(async context =>
{
var errorFeature = context.Features.Get
<IExceptionHandlerPathFeature>();
var exception = errorFeature...