Skip to content

Commit

Permalink
refactor: generalException 일괄 처리 및 logger AOP 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
daeun084 committed Jan 24, 2025
1 parent 2c351eb commit 5492ee0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,55 +26,6 @@
@RequiredArgsConstructor
public class GeneralExceptionAdvice extends ResponseEntityExceptionHandler {

// UserException 처리
@ExceptionHandler(UserException.class)
public ResponseEntity<ApiResponse<Void>> handleUserException(UserException e) {
log.warn(">>>>>>>>UserException: {}", e.getErrorStatus().getMessage());
return ApiResponse.error(e.getErrorStatus());
}

// TokenException 처리
@ExceptionHandler(TokenException.class)
public ResponseEntity<ApiResponse<Void>> handleTokenException(TokenException e) {
log.warn(">>>>>>>>TokenException: {}", e.getErrorStatus().getMessage());
return ApiResponse.error(e.getErrorStatus());
}

// FolderException 처리
@ExceptionHandler(FolderException.class)
public ResponseEntity<ApiResponse<Void>> handleFolderException(FolderException e) {
log.warn(">>>>>>>>FolderException: {}", e.getErrorStatus().getMessage());
return ApiResponse.error(e.getErrorStatus());
}

// RecordException 처리
@ExceptionHandler(RecordException.class)
public ResponseEntity<ApiResponse<Void>> handleRecordException(RecordException e) {
log.warn(">>>>>>>>RecordException: {}", e.getErrorStatus().getMessage());
return ApiResponse.error(e.getErrorStatus());
}

// AnalysisException 처리
@ExceptionHandler(AnalysisException.class)
public ResponseEntity<ApiResponse<Void>> handleAnalysisException(AnalysisException e) {
log.warn(">>>>>>>>AnalysisException: {}", e.getErrorStatus().getMessage());
return ApiResponse.error(e.getErrorStatus());
}

// AbilityException 처리
@ExceptionHandler(AbilityException.class)
public ResponseEntity<ApiResponse<Void>> handleAbilityException(AbilityException e) {
log.warn(">>>>>>>>AbilityException: {}", e.getErrorStatus().getMessage());
return ApiResponse.error(e.getErrorStatus());
}

// ChatException 처리
@ExceptionHandler(ChatException.class)
public ResponseEntity<ApiResponse<Void>> handleChatException(ChatException e) {
log.warn(">>>>>>>>ChatException: {}", e.getErrorStatus().getMessage());
return ApiResponse.error(e.getErrorStatus());
}

// GeneralException 처리
@ExceptionHandler(GeneralException.class)
public ResponseEntity<ApiResponse<Void>> handleGeneralException(GeneralException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}

0 comments on commit 5492ee0

Please sign in to comment.