-
Notifications
You must be signed in to change notification settings - Fork 2
prod : DiscordNotifier 를 통한 에러 실시간 알림 및 부분 포맷 변경 #237
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,18 +23,6 @@ public class GlobalExceptionHandler { | |||||||||||||||||
|
|
||||||||||||||||||
| private final NotifyClientAdapter<DiscordExceptionNotifyEventRequest> notifier; | ||||||||||||||||||
|
|
||||||||||||||||||
| private void notifyIfNeeded(Exception ex) { | ||||||||||||||||||
| try { | ||||||||||||||||||
| DiscordExceptionNotifyEventRequest request = DiscordExceptionNotifyEventRequest.of( | ||||||||||||||||||
| ex.getCause().toString(), | ||||||||||||||||||
| ex.getMessage() | ||||||||||||||||||
| ); | ||||||||||||||||||
| notifier.send(request); | ||||||||||||||||||
| } catch (Exception notifyEx) { | ||||||||||||||||||
| log.error("[Discord Notify Error]", notifyEx); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| @ExceptionHandler(MethodArgumentNotValidException.class) | ||||||||||||||||||
| public ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException( | ||||||||||||||||||
| MethodArgumentNotValidException ex) { | ||||||||||||||||||
|
|
@@ -94,9 +82,9 @@ public ResponseEntity<ErrorResponse> handleAuthenticationException(Authenticatio | |||||||||||||||||
| return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| @ExceptionHandler(life.mosu.mosuserver.global.exception.AuthenticationException.class) | ||||||||||||||||||
| @ExceptionHandler(AuthenticationException.class) | ||||||||||||||||||
| public ResponseEntity<ErrorResponse> handleCustomAuthenticationException( | ||||||||||||||||||
| life.mosu.mosuserver.global.exception.AuthenticationException ex) { | ||||||||||||||||||
| AuthenticationException ex) { | ||||||||||||||||||
| notifyIfNeeded(ex); | ||||||||||||||||||
|
|
||||||||||||||||||
| ErrorResponse response = ErrorResponse.builder() | ||||||||||||||||||
|
|
@@ -160,4 +148,16 @@ public ResponseEntity<ErrorResponse> handleCustomRuntimeException(CustomRuntimeE | |||||||||||||||||
|
|
||||||||||||||||||
| return ResponseEntity.status(ex.getStatus()).body(response); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private void notifyIfNeeded(Exception ex) { | ||||||||||||||||||
| try { | ||||||||||||||||||
| DiscordExceptionNotifyEventRequest request = DiscordExceptionNotifyEventRequest.of( | ||||||||||||||||||
| ex.getCause().toString(), | ||||||||||||||||||
| ex.getMessage() | ||||||||||||||||||
| ); | ||||||||||||||||||
|
Comment on lines
+154
to
+157
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. The call To make the notification more robust, you should handle the case where the cause is null.
Suggested change
|
||||||||||||||||||
| notifier.send(request); | ||||||||||||||||||
| } catch (Exception notifyEx) { | ||||||||||||||||||
| log.error("[Discord Notify Error]", notifyEx); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,7 @@ public static DiscordExceptionNotifyEventRequest of( | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| public String getMessage() { | ||||||||||||||||||
| return "❌ **알림 전송 실패**\n" | ||||||||||||||||||
| return "⚠️ **알림 전송**\n" | ||||||||||||||||||
| + String.format("- ⚠️ exception Cause : `%s`\n", exceptionCause) | ||||||||||||||||||
| + String.format("- 📨 exception Message: `%s`\n", exceptionMessage) | ||||||||||||||||||
| + String.format("- 📋 meta: `%s`", meta == null ? "없음" : meta); | ||||||||||||||||||
|
Comment on lines
+25
to
28
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. Using the If you are using Java 15+, you could also consider using a text block with the
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
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 introduces an ambiguity in exception handling. Both this method (
handleCustomAuthenticationException) andhandleAuthenticationException(line 72) now handleAuthenticationException.class.Due to the import
import org.springframework.security.core.AuthenticationException;on line 14,AuthenticationException.classresolves toorg.springframework.security.core.AuthenticationException.class. This results in two handlers for the same exception, which will cause anIllegalStateExceptionat runtime and prevent the application from starting.To fix this, you should revert to using the fully qualified class name for your custom
AuthenticationExceptionto distinguish it from Spring'sAuthenticationException.