In this short post I describe a handy error-handling middleware, created by Kristian Hellang, that is used to return ProblemDetails results when an exception occurs.

ProblemDetails and the [ApiController] attribute
ASP.NET Core 2.1 introduced the [ApiController] attribute which applies a number of common API-specific conventions to controllers. In ASP.NET Core 2.2 an extra convention was added - transforming error status codes (>= 400) to ProblemDetails.

Returning a consistent type, ProblemDetails, for all errors makes it much easier for consuming clients. All errors from MVC controllers, whether they’re a 400 (Bad Request) or a 404 (Not Found), return a ProblemDetails object:

#asp.net core #error handling

Handling Web API Exceptions with ProblemDetails middleware
20.05 GEEK