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

feat: 전역 예외 처리 #32

Merged
merged 4 commits into from
Oct 7, 2024
Merged

feat: 전역 예외 처리 #32

merged 4 commits into from
Oct 7, 2024

Conversation

dani820
Copy link
Collaborator

@dani820 dani820 commented Sep 28, 2024

이 PR을 통해 해결하려는 문제

  • @RestControllerAdvice를 사용하여 예외 처리를 중앙 집중화함으로써 예외 응집도를 향상시킨다.
  • 에러 응답 dto 생성을 통해 일관된 응답 처리를 도모하고 클라이언트에게 명확한 에러 원인을 전달한다.

추가 및 변경사항

  • Custom Exception과 에러 응답 dto 구성

참고(옵션)

  • error code 추가 중

체크리스트

  • 리뷰어를 지정하였는가
  • 코드가 오류나 경고없이 빌드되는가
  • 추가 및 변경된 사항에 대해 충분히 테스트 하였는가

@dani820 dani820 self-assigned this Sep 28, 2024
@dani820 dani820 marked this pull request as draft September 28, 2024 14:33
import lombok.Getter;

@Getter
public class PostDeletionFailedException extends InMyBookException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

이건 언제 발생하는 에러 일까요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

독서록 삭제 요청 과정에서 db 데이터 삭제 실패한 경우를 생각하고 작성했습니다

Copy link
Collaborator

Choose a reason for hiding this comment

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

해당 에러를 발생 시키는 레이어에 두는건 어떨까요???
예를 들어 해당 에러는 Post 를 삭제 하려고 DB 에 요청했는데 실패 한 것을 인지하고 Usecase 가 외부에 알리려는 에러 라고 하면 usecase 패키지에 두는 방식으로요..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네 각각 연관된 레이어 하위에 두겠습니다~

@dani820 dani820 marked this pull request as ready for review September 29, 2024 05:47
@@ -19,7 +21,8 @@ public Post createPost(RegisterPostCommand registerPostCommand) {
, registerPostCommand.thumbnailImg().getSize()
, registerPostCommand.thumbnailImg().getBytes());
} catch (IOException e) {
throw new RuntimeException("독서록 게시글을 등록할 수 없습니다.");
// throw new RuntimeException("독서록 게시글을 등록할 수 없습니다.");
throw new PostRegistrationFailedException(ErrorCode.INVALID_PARAMETER);
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기 에러 코드는 Invalid_parameter 보다는 어떤 값이 invalid 한지를 정확히 나타내는게 좋을 것 같아요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 알겠습니다


import lombok.extern.slf4j.Slf4j;

@Slf4j
Copy link
Collaborator

Choose a reason for hiding this comment

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

이건 어떻게 동작 할까요~?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

롬복에서 제공하는 @slf4j 어노테이션을 사용하면 컴파일 타임에 log 객체가 생성되어 따로 초기화 코드를 작성해주지 않아도 'log'라는 고정된 변수명을 통해 로그 적용이 가능합�니다. 스프링부트에서는 기본적으로 Logback을 사용하도록 되어있으며 LogBack은 Slf4j의 구현체이므로 해당 어노테이션을 사용해서 로깅 처리 시 LogBack을 통해 로그가 출력됩니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

logback 과 log4j2 의 차이점은 뭘까요?
뭘 사용 하실 건가요???
그리고 스프링에서 기본적으로 설정되어있는 logback 을 log4j 로 변경 하려면 어떻게 해야 할까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

logback과 log4j2의 가장 큰 차이점은 비동기 로거 제공 여부에 있습니다. log4j2는 비동기 로거를 지원함으로써 멀티 스레드 환경에서 많은 처리량과 짧은 대기 시간을 제공합니다. 그 외에도 람다식에 기반한 lazy evaluation 지원, GC 작동에 의한 지연 회피를 위해 garbage-free mode 도 지원하는 등 여러 성능 상의 이점이 있다고 판단되어 log4j2를 사용할 예정입니다.

log4j2로 변경하기 위해서는 spring-boot-starter에 포함되어 있는 spring-boot-starter-logging 프레임워크 제거 후 spring-boot-starter-log4j2 프레임워크를 추가하면 됩니다.

@dani820 dani820 changed the title feature: 전역 예외 처리 feat: 전역 예외 처리 Oct 6, 2024
Copy link
Collaborator

@f-lab-bradley f-lab-bradley left a comment

Choose a reason for hiding this comment

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

생각하신 예외 상황에서 생각하신 에러들이 잘 나오는지 확인 해 보시고 머지 진행 하세요~

@dani820 dani820 merged commit 817595b into develop Oct 7, 2024
1 check passed
@dani820 dani820 deleted the feature/31 branch October 7, 2024 12:27
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.

2 participants