Dotnet core web api exception best practice
Currently, I have found 3 ways to do centralized error handling
- Add a custom exception middleware
- Config in
app.UseExceptionHandler()with anonymous function - 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?
0 comments:
Post a Comment