-
Notifications
You must be signed in to change notification settings - Fork 0
전역 예외 처리 및 공통 예외 구조 구현 #5
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
TTaiJin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
문제 없는 거 같습니다
InJunKangW
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생 많으셨습니다~
| @Override | ||
| public ResponseEntity<Object> handleMethodArgumentNotValid( | ||
| MethodArgumentNotValidException e, | ||
| @NonNull HttpHeaders headers, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
headers랑 status 파라미터 안 쓰는 걸로 보이는데 맞나요?
맞으면 혹시 이 파라미터는 왜 필요한가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 headers와 status 파라미터는 직접 사용하고 있지 않지만, 이 메서드는 ResponseEntityExceptionHandler가 정의한 오버라이드 대상 메서드입니다. 따라서 시그니처 그대로 맞춰서 오버라이드하기 위해 작성이 필요합니다.
커스텀 응답 객체를 반환하고 있어서 직접 활용하고 있지 않지만,필요 시 응답 헤더를 추가하거나 상태 코드를 조정할 수 있도록 하기 위해 시그니처에 포함되어 있는거로 알고 있습니다.
| } | ||
|
|
||
| @ExceptionHandler({Exception.class}) | ||
| public ResponseEntity<ApiErrorResponse> handleAllException(Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 경우 로그에 HttpMethod나 API 경로 같은게 포함되면 더 로그 파악이 좋을 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그럴 수 있겠네요. 확인 감사합니다
|
lgtm |
|
Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
|



작업사항
1. 공통 예외 구조 생성
ErrorCode인터페이스 정의ServiceException상위 예외 클래스 정의→ 도메인 간 공통으로 사용 가능한 예외 클래스
2. 전역 예외 처리 구성
GlobalExceptionHandler생성@Valid실패 → 400IllegalArgumentException→ 400Log4uException(도메인 예외) → 커스텀 상태 반환ApiErrorResponse→ 모든 예외를 한곳에서 통일된 방식으로 처리
→ 각 예외에 대한 로깅( 적절한 로그 레벨 여부는 추후 확인)
3. 외부 API 예외 처리 구성
ApiResponseErrorHandler(RestTemplate ResponseErrorHandler)ExternalApiRequestException정의ClientConfig를 통해 RestTemplate에 커스텀 핸들러 등록→ 외부 API 호출 실패에 대해 일관된 처리 및 로깅
4. 도메인별 예외 사용 예시 추가
CommentErrorCode,CommentException,NotFoundCommentException예시 추가→ 각 도메인에 대해서 동일한 패턴으로 exception 생성하여 사용