Amichai Mantinband’s Post

View profile for Amichai Mantinband, graphic

Software Engineer at Microsoft

Error handling in ASP.NET - Part 2 💪 In Part 1, I demonstrated how we can use the "UseExceptionHandler" method to add a middleware that will catch uncaught exceptions, reset the request path and re-execute it. This allowed us to specify a controller method that will handle this error flow. One of the big advantages of this solution is being able to use the base controller's methods. In the example from part 1, we used the "Problem(..)" method which creates the Problem Details response. Usually, we would like to customize the Problem Details response, adding some debugging data or other custom properties. By default, the DefaultProblemDetailsFactory (source code: https://lnkd.in/dJd7Y4uE) is used to create the Problem Details. In this part, we will show how we can create our custom ProblemDetailsFactory which will be used by all controllers to build the Problem Details response. Other than the "AddCustomProperties" method in the factory, the code is almost exactly the same as the original code from the DefaultProblemDetailsFactory. Have any of you implemented your own problem details factory? A sample project containing the minimum code needed for the example below is available on my GitHub: https://lnkd.in/dSP4ffYV Error handling in ASP.NET: Part 1: https://lnkd.in/dcaYG75m Part 3: https://www.linkedin.com/posts/amichaim_aspnetcore-aspnet-dotnetcore-activity-6865617913924087808-QmYI #aspnetcore #aspnet #dotnetcore #netcore #netcore5 #csharp9

  • No alternative text description for this image

To view or add a comment, sign in

Explore topics