Skip to content

Conversation

@dnzp75
Copy link
Collaborator

@dnzp75 dnzp75 commented Mar 25, 2025

작업사항

1. 공통 예외 구조 생성

  • ErrorCode 인터페이스 정의
  • ServiceException 상위 예외 클래스 정의

→ 도메인 간 공통으로 사용 가능한 예외 클래스

2. 전역 예외 처리 구성

  • GlobalExceptionHandler 생성
    • @Valid 실패 → 400
    • IllegalArgumentException → 400
    • Log4uException (도메인 예외) → 커스텀 상태 반환
    • 그 외 예외 → 500으로 통일
  • 예외 응답 포맷: ApiErrorResponse

→ 모든 예외를 한곳에서 통일된 방식으로 처리
→ 각 예외에 대한 로깅( 적절한 로그 레벨 여부는 추후 확인)

3. 외부 API 예외 처리 구성

  • ApiResponseErrorHandler (RestTemplate ResponseErrorHandler)
  • ExternalApiRequestException 정의
  • ClientConfig를 통해 RestTemplate에 커스텀 핸들러 등록

→ 외부 API 호출 실패에 대해 일관된 처리 및 로깅

4. 도메인별 예외 사용 예시 추가

  • CommentErrorCode, CommentException, NotFoundCommentException 예시 추가
  • 도메인별로 동일한 패턴으로 사용하도록 하는 가이드 목적

→ 각 도메인에 대해서 동일한 패턴으로 exception 생성하여 사용

@dnzp75 dnzp75 added the enhancement New feature or request label Mar 25, 2025
@dnzp75 dnzp75 requested review from a user, InJunKangW, TTaiJin and sapiens2000 March 25, 2025 09:27
@dnzp75 dnzp75 self-assigned this Mar 25, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Collaborator

@TTaiJin TTaiJin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문제 없는 거 같습니다

Copy link
Collaborator

@InJunKangW InJunKangW left a 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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headers랑 status 파라미터 안 쓰는 걸로 보이는데 맞나요?
맞으면 혹시 이 파라미터는 왜 필요한가요?

Copy link
Collaborator Author

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 경우 로그에 HttpMethod나 API 경로 같은게 포함되면 더 로그 파악이 좋을 것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그럴 수 있겠네요. 확인 감사합니다

@sapiens2000
Copy link
Collaborator

lgtm

@cr-gpt
Copy link

cr-gpt bot commented Mar 26, 2025

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

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sonarqubecloud
Copy link

@dnzp75 dnzp75 merged commit f14f65a into develop Mar 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants