From 5492ee0f0ed918709a19b23549bda6b79c356d61 Mon Sep 17 00:00:00 2001 From: daeun084 <030804jk@naver.com> Date: Fri, 24 Jan 2025 22:03:55 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20generalException=20=EC=9D=BC?= =?UTF-8?q?=EA=B4=84=20=EC=B2=98=EB=A6=AC=20=EB=B0=8F=20logger=20AOP=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GeneralExceptionAdvice.java | 56 ------------------- .../common/log/discord/DiscordLoggerAop.java | 11 ++-- 2 files changed, 7 insertions(+), 60 deletions(-) diff --git a/src/main/java/corecord/dev/common/exception/GeneralExceptionAdvice.java b/src/main/java/corecord/dev/common/exception/GeneralExceptionAdvice.java index 294416e..bb034f8 100644 --- a/src/main/java/corecord/dev/common/exception/GeneralExceptionAdvice.java +++ b/src/main/java/corecord/dev/common/exception/GeneralExceptionAdvice.java @@ -2,13 +2,6 @@ import corecord.dev.common.response.ApiResponse; import corecord.dev.common.status.ErrorStatus; -import corecord.dev.domain.ability.exception.AbilityException; -import corecord.dev.domain.analysis.exception.AnalysisException; -import corecord.dev.domain.auth.exception.TokenException; -import corecord.dev.domain.chat.exception.ChatException; -import corecord.dev.domain.folder.exception.FolderException; -import corecord.dev.domain.record.exception.RecordException; -import corecord.dev.domain.user.exception.UserException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.support.DefaultMessageSourceResolvable; @@ -33,55 +26,6 @@ @RequiredArgsConstructor public class GeneralExceptionAdvice extends ResponseEntityExceptionHandler { - // UserException 처리 - @ExceptionHandler(UserException.class) - public ResponseEntity> handleUserException(UserException e) { - log.warn(">>>>>>>>UserException: {}", e.getErrorStatus().getMessage()); - return ApiResponse.error(e.getErrorStatus()); - } - - // TokenException 처리 - @ExceptionHandler(TokenException.class) - public ResponseEntity> handleTokenException(TokenException e) { - log.warn(">>>>>>>>TokenException: {}", e.getErrorStatus().getMessage()); - return ApiResponse.error(e.getErrorStatus()); - } - - // FolderException 처리 - @ExceptionHandler(FolderException.class) - public ResponseEntity> handleFolderException(FolderException e) { - log.warn(">>>>>>>>FolderException: {}", e.getErrorStatus().getMessage()); - return ApiResponse.error(e.getErrorStatus()); - } - - // RecordException 처리 - @ExceptionHandler(RecordException.class) - public ResponseEntity> handleRecordException(RecordException e) { - log.warn(">>>>>>>>RecordException: {}", e.getErrorStatus().getMessage()); - return ApiResponse.error(e.getErrorStatus()); - } - - // AnalysisException 처리 - @ExceptionHandler(AnalysisException.class) - public ResponseEntity> handleAnalysisException(AnalysisException e) { - log.warn(">>>>>>>>AnalysisException: {}", e.getErrorStatus().getMessage()); - return ApiResponse.error(e.getErrorStatus()); - } - - // AbilityException 처리 - @ExceptionHandler(AbilityException.class) - public ResponseEntity> handleAbilityException(AbilityException e) { - log.warn(">>>>>>>>AbilityException: {}", e.getErrorStatus().getMessage()); - return ApiResponse.error(e.getErrorStatus()); - } - - // ChatException 처리 - @ExceptionHandler(ChatException.class) - public ResponseEntity> handleChatException(ChatException e) { - log.warn(">>>>>>>>ChatException: {}", e.getErrorStatus().getMessage()); - return ApiResponse.error(e.getErrorStatus()); - } - // GeneralException 처리 @ExceptionHandler(GeneralException.class) public ResponseEntity> handleGeneralException(GeneralException e) { diff --git a/src/main/java/corecord/dev/common/log/discord/DiscordLoggerAop.java b/src/main/java/corecord/dev/common/log/discord/DiscordLoggerAop.java index 94240a6..67de99f 100644 --- a/src/main/java/corecord/dev/common/log/discord/DiscordLoggerAop.java +++ b/src/main/java/corecord/dev/common/log/discord/DiscordLoggerAop.java @@ -26,12 +26,15 @@ public void generalExceptionErrorLoggerExecute() {} @Before("generalExceptionErrorLoggerExecute()") public void serverErrorLogging(JoinPoint joinpoint) { - Object[] args = joinpoint.getArgs(); - GeneralException exception = (GeneralException) args[0]; HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); + Object[] args = joinpoint.getArgs(); - if (exception.getErrorStatus().getHttpStatus() == HttpStatus.INTERNAL_SERVER_ERROR) + if (args[0] instanceof GeneralException exception) { + if (exception.getErrorStatus().getHttpStatus() == HttpStatus.INTERNAL_SERVER_ERROR) + discordAlarmSender.sendDiscordAlarm(exception, request); + } else { + Exception exception = (Exception) args[0]; discordAlarmSender.sendDiscordAlarm(exception, request); + } } - }