-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from kakao-tech-campus-2nd-step3/develop
* ExceptionAdvice 정의 (#4) * build: lombok 추가 #3 * chore: build.gradle 정리 #3 * chore: ApplicationError 정의 #3 * chore: BusinessError 정의 #3 * feat: ExceptionAdvice 정의 - BusinessError - ApplicationError #3 * chore: exception -> error 패키지명 수정 #3 * chore: error logging 방식 수정 - [] : {} #3 * DOCS : PR template 업데이트 --------- Co-authored-by: 정지민 <[email protected]> Co-authored-by: amm0124 <[email protected]>
- Loading branch information
Showing
7 changed files
with
114 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
## TO-DO | ||
## 해결하려는 문제가 무엇인가요? | ||
|
||
어떤 것을 하셨나요? | ||
어떤 것 작업했는지 작성해주세요! 아래는 예시입니다. | ||
자세하면 자세할수록 좋습니다! | ||
- close # | ||
|
||
- [ ] build.gradle 의존성 추가 | ||
- [ ] login controller 구현 | ||
- [ ] 파이팅 ~ | ||
## 어떻게 해결했나요? | ||
|
||
## 추가 정보 | ||
- | ||
|
||
하고 싶은 말이 있으면 작성해주세요! | ||
## 코드 리뷰시 요청 사항 | ||
|
||
## 리뷰어 | ||
- | ||
|
||
꼭 봐줬으면 하는 사람이 있으면 @<< 를 통해서 태그! | ||
|
||
|
||
## 관련 이슈 닫기 | ||
|
||
closes (#이슈 번호) | ||
## 더 하고 싶은 말 | ||
|
||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package poomasi.global.error; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ApplicationError { | ||
EXAMPLE_ERROR("애플리케이션 에러 예시입니다."); | ||
|
||
private final String message; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/poomasi/global/error/ApplicationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package poomasi.global.error; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class ApplicationException extends RuntimeException { | ||
private final ApplicationError applicationError; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package poomasi.global.error; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum BusinessError { | ||
EXAMPLE_ERROR(HttpStatus.BAD_REQUEST, "에러 예시입니다."); | ||
|
||
private final HttpStatus httpStatus; | ||
|
||
private final String message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package poomasi.global.error; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class BusinessException extends RuntimeException { | ||
private final BusinessError businessError; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package poomasi.global.error; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.ErrorResponse; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class ExceptionAdvice { | ||
|
||
@ExceptionHandler(BusinessException.class) | ||
public ErrorResponse businessExceptionHandler(BusinessException exception) { | ||
BusinessError businessError = exception.getBusinessError(); | ||
log.warn("[{}] : {}", businessError.name(), businessError.getMessage()); | ||
return ErrorResponse | ||
.builder(exception, businessError.getHttpStatus(), businessError.getMessage()) | ||
.title(businessError.name()) | ||
.build(); | ||
} | ||
|
||
@ExceptionHandler(ApplicationException.class) | ||
public ErrorResponse applicationExceptionHandler(ApplicationException exception) { | ||
ApplicationError applicationError = exception.getApplicationError(); | ||
log.error("[{}] : {}", applicationError.name(), applicationError.getMessage(), | ||
exception); | ||
return ErrorResponse | ||
.builder(exception, HttpStatus.INTERNAL_SERVER_ERROR, applicationError.getMessage()) | ||
.title(exception.getClass().getSimpleName()) | ||
.build(); | ||
} | ||
} |