Wednesday, April 24, 2019

Dotnet core web api exception best practice

Currently, I have found 3 ways to do centralized error handling

  1. Add a custom exception middleware
  2. Config in app.UseExceptionHandler() with anonymous function
  3. Set object in controller helper methods like BadRequest(new { Message = "invalid input"})

In the official doc, the recommended way is the second one, but I think the third one is very easy to use. I want to generate JSON error response and write error log, how should I implement my error handler?

Dotnet core web api exception best practice Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team