-
Notifications
You must be signed in to change notification settings - Fork 2
fix: Update exception handler to use fully qualified class name for A… #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,9 +82,9 @@ public ResponseEntity<ErrorResponse> handleAuthenticationException(Authenticatio | |
| return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(AuthenticationException.class) | ||
| @ExceptionHandler(life.mosu.mosuserver.global.exception.AuthenticationException.class) | ||
| public ResponseEntity<ErrorResponse> handleCustomAuthenticationException( | ||
| AuthenticationException ex) { | ||
| life.mosu.mosuserver.global.exception.AuthenticationException ex) { | ||
|
Comment on lines
+85
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this change is correct, the handler's implementation introduces two maintainability concerns:
I recommend refactoring to address both issues. You could extract the common response-building logic into a private helper method. This helper could then check the exception type to include specific details like Addressing this would significantly improve the maintainability and observability of your exception handling. This can be done in a follow-up PR. |
||
| notifyIfNeeded(ex); | ||
|
|
||
| ErrorResponse response = ErrorResponse.builder() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change correctly wires up the handler for your custom
AuthenticationException. However, the handler itself has a critical issue that this change will now expose.The call to
notifyIfNeeded(ex)on line 88 can lead to aNullPointerException. InsidenotifyIfNeeded(line 152), the codeex.getCause().toString()is executed without checking ifex.getCause()isnull.Your custom
life.mosu.mosuserver.global.exception.AuthenticationExceptionis instantiated without a cause, soex.getCause()will benullfor it. This will crash the exception handler, masking the original error.This needs to be fixed urgently. The
notifyIfNeededmethod should be updated to handle null causes gracefully. For example:Since this fix is outside the changed lines, please address it in a follow-up PR, but it is critical.