Feature/85/implement global error handler middleware - #90
Conversation
|
emil720a1
left a comment
There was a problem hiding this comment.
Before approval, please address the following issues:
-
This branch is behind the latest dev. dev already registers AddProblemDetails(), ValidationExceptionHandler, and UseExceptionHandler(). Please rebase or merge the latest dev, remove the duplicate ProblemDetails/middleware registrations, and register GlobalExceptionHandler after ValidationExceptionHandler. The order is important: validation exceptions must remain 400 responses, while only unhandled exceptions should reach the global 500 handler.
-
GlobalExceptionHandler currently returns false when IProblemDetailsService cannot write the response. Returning false tells ExceptionHandlerMiddleware that the exception was not handled. Please follow the existing ValidationExceptionHandler approach: write ProblemDetails using WriteAsJsonAsync as a fallback and return true. The current test expecting false should be replaced with a fallback-response test.
-
Please add middleware-level integration coverage for the interaction between ValidationExceptionHandler and GlobalExceptionHandler: validation exceptions should remain 400, while an unhandled exception should produce a 500 application/problem+json response containing a traceId and no sensitive exception message.
Also, please add the missing newline at the end of the two newly added files.


JIRA
Code reviewers
Second Level Review
Summary of issue
The API did not have centralized handling for unhandled exceptions. This could result in inconsistent error responses, duplicated exception-handling logic, and potential exposure of internal implementation details.
A global exception-handling mechanism was required to log unexpected errors and return a consistent, secure response to API clients.
Summary of change
GlobalExceptionHandlerusing the .NET 10IExceptionHandlerinterface.AddExceptionHandler<GlobalExceptionHandler>().IProblemDetailsServicethroughAddProblemDetails().500 Internal Server Errorresponses usingProblemDetails.traceIdto error responses for correlation with server logs.CHECK LIST
closes #85