eunja511005 / AutoCoding

0 stars 0 forks source link

유저 요청 히스토리 저장 로직 변경 - 오류 발생해도 다음 로직 수행, 오류 테이블에는 저장 #87

Open eunja511005 opened 1 year ago

eunja511005 commented 1 year ago
  1. 요청 히스토리 저장시 오류 발생해도 다음 프로세스 진행 되도록 변경
  2. 오류 내용 저장

    • com.eun 패키지 하위 모든 메서드에서 오류 발생시 에러 테이블에 저장 하도록 AOP 등록
      
      @Aspect
      @Component
      @RequiredArgsConstructor
      public class ExceptionLoggingAspect {

    private final ZthhErrorService zthhErrorService;

    @AfterThrowing(pointcut = "execution( com.eun...*(..))", throwing = "exception") public void handleException(JoinPoint joinPoint, Exception exception) { saveErrorLog(exception); }

    private void saveErrorLog(Exception exception) { String errorMessage = org.apache.tika.utils.ExceptionUtils.getStackTrace(exception);

    if (errorMessage.length() > 2000) {
        errorMessage = errorMessage.substring(0, 2000);
    }
    
    zthhErrorService.save(
            ZthhErrorDTO.builder().errorMessage("GlobalExceptionHandler Error : " + errorMessage).build());
    
    exception.printStackTrace();

    } }