Skip to content

Commit

Permalink
Merge pull request #8 from KUSITMS-MOAMOA/chore/#7
Browse files Browse the repository at this point in the history
[Chore/#7] 디스코드 알림 범위 축소
  • Loading branch information
oosedus authored Jan 25, 2025
2 parents 32aab41 + c450a3b commit 7e02b78
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,29 @@ public class DiscordLoggerAop {

private final DiscordAlarmSender discordAlarmSender;

@Pointcut("execution(* corecord.dev.common.exception.GeneralExceptionAdvice..*(..))")
@Pointcut("execution(* corecord.dev.common.exception.GeneralExceptionAdvice.handleGeneralException())")
public void generalExceptionErrorLoggerExecute() {}

@Pointcut("execution(* corecord.dev.common.exception.GeneralExceptionAdvice.handleException())")
public void serverExceptionErrorLoggerExecute() {}

@Pointcut("execution(* corecord.dev.common.exception.GeneralExceptionAdvice.handleNullPointerException())")
public void nullPointerExceptionErrorLoggerExecute() {}

@Before("generalExceptionErrorLoggerExecute()")
public void serverErrorLogging(JoinPoint joinpoint) {
public void generalExceptionLogging(JoinPoint joinpoint) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
Object[] args = joinpoint.getArgs();
GeneralException exception = (GeneralException)joinpoint.getArgs()[0];

if (args[0] instanceof GeneralException exception) {
if (exception.getErrorStatus().getHttpStatus() == HttpStatus.INTERNAL_SERVER_ERROR)
discordAlarmSender.sendDiscordAlarm(exception, request);
} else {
Exception exception = (Exception) args[0];
if (exception.getErrorStatus().getHttpStatus() == HttpStatus.INTERNAL_SERVER_ERROR)
discordAlarmSender.sendDiscordAlarm(exception, request);
}
}

@Before("serverExceptionErrorLoggerExecute() & nullPointerExceptionErrorLoggerExecute()")
public void serverExceptionLogging(JoinPoint joinpoint) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
Exception exception = (Exception)joinpoint.getArgs()[0];

discordAlarmSender.sendDiscordAlarm(exception, request);
}
}

0 comments on commit 7e02b78

Please sign in to comment.