Skip to content
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

[Mod] Error log 처리 방식 수정 #176

Closed
wants to merge 4 commits into from
Closed

[Mod] Error log 처리 방식 수정 #176

wants to merge 4 commits into from

Conversation

jjjh02
Copy link
Contributor

@jjjh02 jjjh02 commented Mar 12, 2025

수정한 코드

  • ErrorCode: 비즈니스로직 에러메시지 수정
  • LoggingAspect: errorlog에 GeneralExceptionexceptionName으로 수정
  • GlobalExceptionHandler: Dto에 잘못된 데이터타입으로 데이터가 들어온 경우 발생하는 HttpMessageNotReadableException 다루는 exceptionhandler 추가
  • PreparationScheduleService, PreparationUserService, ScheduleService: EntityNotFoundException, AccessDeniedException와 같은 Exception을 GeneralException으로 처리 (Api 응답 통일 및 비즈니스 로직에서 발생하는 예외는 generalException으로 처리하는 것이 적절)

문제

  • 특정 api로 요청하고 GeneralException에서 처리하지않는 예외가 발생할시, apiLog에서 request.getRequestURI()/error로 저장됨
  • apiLog를 저장할 때, requestUrl이 /error로 나와 어느 api에서 에러가 발생한지 확인이 어려움

문제 이유

  • Spring Boot에서는 내부적으로 Internal Server Error가 발생하면 요청 URL이 /error로 나옴
  • Exception이 발생하면, Spring의 BasicErrorController가 /error 경로로 리디렉션하여 에러 페이지를 반환
    -> request.getRequestURI()를 호출하면 /error가 반환될 수 있음

해결방법

  • 비즈니스 로직 내부에서 발생한 EntityNotFoundException, .. 와 같은 exception을 Generalexception 으로 처리를 바꾸면 requestUrl이 사용한 메서드로 저장됨

추가적으로 수정한 부분

  • dto가 유효하지 않아서 오는 에러는 HttpMessageNotReadableException로 컨트롤러 실행전에 발생하는 예외로, AOP(LoggingAspect)는 컨트롤러 메서드가 실행될 때 동작하기 때문에 컨트롤러 실행 전 예외는 LoggingAspect에서 감지되지 않음
  • ExceptionHandler에서 errorllog 출력

결과

AOP(LoggingAspect)
: api request 로그, api error 중 내부 로직 exception 로그를 Db에 저장 및 출력

ExceptionHandler
: 컨트롤러 실행 전 예외는 로그로 출력

@github-actions github-actions bot closed this Mar 12, 2025
Copy link

실패하는 테스트코드가 있어 PR이 자동으로 닫혔습니다.
Github Action에서 자세한 실패 로그를 확인하고 코드를 수정하세요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant