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

[BLOOM-009] 예외 응답 처리 리팩토링 #12

Merged
merged 6 commits into from
Jul 25, 2024
Merged

Conversation

Dompoo
Copy link
Collaborator

@Dompoo Dompoo commented Jul 24, 2024

How

  • HttpStatus와 message를 담는 ErrorType 생성
  • ErrorResponse와 커스텀 예외가 ErrorType을 참조하도록 수정
  • 기존 커스텀 예외들을 이에 맞게 수정

Result

  • 반복되는 코드가 확실히 줄었습니다.
  • 예외와 예외 응답의 결합이 느슨해져, 추후 로깅과 응답을 가공할 때 편할 것 같습니다.

@Dompoo Dompoo added the 💊 refactor Suggest code improvements or refactoring label Jul 24, 2024
@Dompoo Dompoo requested a review from stophwan July 24, 2024 17:45
@Dompoo Dompoo self-assigned this Jul 24, 2024
@Dompoo Dompoo linked an issue Jul 24, 2024 that may be closed by this pull request
@@ -1,5 +1,5 @@
<!-- 제목은 아래처럼 -->
<!-- [#이슈번호] PR 제목 -->
<!-- [BLOOM-001] PR 제목 -->
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines 8 to 16
class GlobalExceptionHandler {
@ExceptionHandler(MyException::class)
fun handleMyException(exception: MyException): ResponseEntity<ErrorResponse> {
val errorType = exception.errorType
return ResponseEntity
.status(exception.status)
.body(ErrorResponse.from(exception))
.status(errorType.status)
.body(ErrorResponse.from(errorType))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

RestControllerAdvice에서 log도 출력을 해야하는데 ErrorType에 Log 레벨을 추가하는게 좋을 것 같아요~
여기서는 when으로 분기처리하고요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

추가했습니다~!

Copy link
Member

@stophwan stophwan left a comment

Choose a reason for hiding this comment

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

LGTM~ 💚

@Dompoo Dompoo merged commit 5ef6cdb into main Jul 25, 2024
2 checks passed
@Dompoo Dompoo deleted the refactor/error-response branch July 26, 2024 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💊 refactor Suggest code improvements or refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[refactor] 예외 응답 기능 리팩토링
2 participants