-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: 전역 예외 처리 #32
Conversation
import lombok.Getter; | ||
|
||
@Getter | ||
public class PostDeletionFailedException extends InMyBookException { |
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.
이건 언제 발생하는 에러 일까요??
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.
독서록 삭제 요청 과정에서 db 데이터 삭제 실패한 경우를 생각하고 작성했습니다
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.
해당 에러를 발생 시키는 레이어에 두는건 어떨까요???
예를 들어 해당 에러는 Post 를 삭제 하려고 DB 에 요청했는데 실패 한 것을 인지하고 Usecase 가 외부에 알리려는 에러
라고 하면 usecase 패키지에 두는 방식으로요..
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.
네 각각 연관된 레이어 하위에 두겠습니다~
@@ -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); |
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.
여기 에러 코드는 Invalid_parameter 보다는 어떤 값이 invalid 한지를 정확히 나타내는게 좋을 것 같아요.
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.
넵 알겠습니다
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j |
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.
이건 어떻게 동작 할까요~?
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.
롬복에서 제공하는 @slf4j 어노테이션을 사용하면 컴파일 타임에 log 객체가 생성되어 따로 초기화 코드를 작성해주지 않아도 'log'라는 고정된 변수명을 통해 로그 적용이 가능합�니다. 스프링부트에서는 기본적으로 Logback을 사용하도록 되어있으며 LogBack은 Slf4j의 구현체이므로 해당 어노테이션을 사용해서 로깅 처리 시 LogBack을 통해 로그가 출력됩니다.
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.
logback 과 log4j2 의 차이점은 뭘까요?
뭘 사용 하실 건가요???
그리고 스프링에서 기본적으로 설정되어있는 logback 을 log4j 로 변경 하려면 어떻게 해야 할까요?
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.
logback과 log4j2의 가장 큰 차이점은 비동기 로거 제공 여부에 있습니다. log4j2는 비동기 로거를 지원함으로써 멀티 스레드 환경에서 많은 처리량과 짧은 대기 시간을 제공합니다. 그 외에도 람다식에 기반한 lazy evaluation 지원, GC 작동에 의한 지연 회피를 위해 garbage-free mode 도 지원하는 등 여러 성능 상의 이점이 있다고 판단되어 log4j2를 사용할 예정입니다.
log4j2로 변경하기 위해서는 spring-boot-starter에 포함되어 있는 spring-boot-starter-logging 프레임워크 제거 후 spring-boot-starter-log4j2 프레임워크를 추가하면 됩니다.
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.
생각하신 예외 상황에서 생각하신 에러들이 잘 나오는지 확인 해 보시고 머지 진행 하세요~
이 PR을 통해 해결하려는 문제
추가 및 변경사항
참고(옵션)
error code 추가 중체크리스트