-
Notifications
You must be signed in to change notification settings - Fork 0
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 #23 from hyundai-fruitfruit/HEENDY-79-exception-re…
…sponse [Heendy 79 exception response] 예외 응답 형식 설정 및 예외 처리 추가
- Loading branch information
Showing
12 changed files
with
196 additions
and
47 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
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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/hyundai/app/exception/ErrorResponse.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,20 @@ | ||
package com.hyundai.app.exception; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
/** | ||
* @author 황수영 | ||
* @since 2024/02/28 | ||
* 예외 응답 형식 | ||
*/ | ||
@Getter | ||
@Builder | ||
@RequiredArgsConstructor | ||
public class ErrorResponse { | ||
private final String errorMessage; | ||
private final String errorType; | ||
private final HttpStatus httpStatus; | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/com/hyundai/app/exception/ExceptionResponseHandler.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,69 @@ | ||
package com.hyundai.app.exception; | ||
|
||
import lombok.extern.log4j.Log4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; | ||
|
||
/** | ||
* @author 황수영 | ||
* @since 2024/02/28 | ||
* 예외 응답 반환하는 핸들러 | ||
*/ | ||
@Log4j | ||
@RestControllerAdvice | ||
public class ExceptionResponseHandler extends ResponseEntityExceptionHandler { | ||
|
||
/** | ||
* @author 황수영 | ||
* @since 2024/02/28 | ||
* 자체 예외 응답 처리 | ||
*/ | ||
@ExceptionHandler(AdventureOfHeendyException.class) | ||
public ResponseEntity<Object> handleCustomException(AdventureOfHeendyException e) { | ||
return handleExceptionInternal(e); | ||
} | ||
|
||
/** | ||
* @author 황수영 | ||
* @since 2024/02/28 | ||
* 자체 예외 이외의 모든 예외 처리 | ||
*/ | ||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<Object> handleAllException(Exception e) { | ||
return handleExceptionAll(e); | ||
} | ||
|
||
/** | ||
* @author 황수영 | ||
* @since 2024/02/28 | ||
* 자체 예외 ResponseEntity 생성 | ||
*/ | ||
private ResponseEntity<Object> handleExceptionInternal(AdventureOfHeendyException e) { | ||
log.error("자체 예외 발생 : " + e); | ||
|
||
return ResponseEntity.status(e.getErrorCode().getHttpStatus()) | ||
.body(ErrorResponse.builder() | ||
.errorMessage(e.getErrorCode().getMessage()) | ||
.errorType(String.valueOf(e.getErrorCode())) | ||
.httpStatus(e.getErrorCode().getHttpStatus()) | ||
.build()); | ||
} | ||
|
||
/** | ||
* @author 황수영 | ||
* @since 2024/02/28 | ||
* 자체 예외 이외의 모든 ResponseEntity 생성 | ||
*/ | ||
private ResponseEntity<Object> handleExceptionAll(Exception e) { | ||
log.error("예외 발생 : " + e); | ||
|
||
return ResponseEntity.status(ErrorCode.SERVER_UNAVAILABLE.getHttpStatus()) | ||
.body(ErrorResponse.builder() | ||
.errorMessage(e.getMessage()) | ||
.errorType(e.toString()) | ||
.httpStatus(ErrorCode.SERVER_UNAVAILABLE.getHttpStatus()) | ||
.build()); | ||
} | ||
} |
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
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
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
Oops, something went wrong.