ProblemDetails is an open source ASP.NET Core middleware developed by Kristian Hellang that can be used to generate detailed results for the exceptions that occur in your application. It handles exceptions in your middleware pipeline, and converts them to ProblemDetails.
Here is a picture of Kristian Hellang. Good job Kristian!
For Adding ProblemDetail to .Net Core Please follow the below steps.
· Install-Package — Hellang.Middleware.ProblemDetails
· Add AddProblemDetails in the Configure service section
· Add app.UseProblemDetails() in the Configure Section
That’s it. Now whenever there is an exception occurring in our application, we will be getting a standard type of message like this:
If we want to give customized error message we can give as below,
And the response will be..
Also if you require detailed information returned for an unhandled exception, we can give like the following way:
the response will be:
Just give it a try and let me know how it goes:
Thanks for reading!