In this post I describe the ProblemDetailsMiddleware by Kristian Hellang that can be used to return ProblemDetails when an exception occurs in an API
With asp.net core do not create your own Exception handling middleware, but use Hellang.Middleware.ProblemDetails to return standard RFC7807 ProblemDetails responses in case of an error.
Read this good article presenting ProblemDetails Middleware
If you want to include exception message in the response - use this config code
options.Map<Exception>((_, ex) =>
{
var details = StatusCodeProblemDetails.Create(StatusCodes.Status500InternalServerError);
details.Detail = ex.GetBaseException().Message;
return details;
});
Place UseProblemDetails() as early as possible before auth and routing, but if you need ProblemDetails object in some other middleware it has to be before this (like logging response exceptions).
Learn what are the most important API security threats engineering leaders should be aware of and steps you can take to prevent them
I’ve been working with Restful APIs for some time now and one thing that I love to do is to talk about APIs.
The method used for this initial research was to obtain a list of the ASX100 (as of 18 September 2020). Then work through each company looking at the following
What is API product management and what can you be doing to be a better API product manager — get aligned with SaaS and enterprise software requirements. This guide lays out what is API product management and some of the things you should be doing to be a good product manager.
APIs are perceived as reliable—more than half of respondents stated that APIs do not break, stop working, or materially change specification often enough to matter.