Skip to content

Commit 8e7eac5

Browse files
committed
♻️ 리뷰 반영 수정 및 예외 로그 추가
1 parent 314a581 commit 8e7eac5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public enum CommonErrorCode implements ErrorCode {
1111
BAD_REQUEST_DATA("E400001", HttpStatus.BAD_REQUEST, "잘못된 요청 데이터입니다."),
1212
INVALID_PAGINATION("E400006", HttpStatus.BAD_REQUEST, "page와 size는 1 이상의 정수여야 합니다."),
1313
INTERNAL_SERVER_ERROR(
14-
"E500001", HttpStatus.INTERNAL_SERVER_ERROR, "서버에러가 발생했습니다. 관리자에게 문의해주세요.");
14+
"E500001", HttpStatus.INTERNAL_SERVER_ERROR, "서버에러가 발생했습니다. 관리자에게 문의해주세요."),
15+
INVALID_JSON_FORMAT("E400008", HttpStatus.BAD_REQUEST, "요청 형식이 올바르지 않습니다. JSON 문법을 확인해주세요.");
1516

1617
private final String code;
1718

backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
import io.f1.backend.global.exception.errorcode.ErrorCode;
66
import io.f1.backend.global.exception.response.ErrorResponse;
77

8+
import lombok.extern.slf4j.Slf4j;
89
import org.springframework.http.ResponseEntity;
10+
import org.springframework.http.converter.HttpMessageNotReadableException;
911
import org.springframework.validation.FieldError;
1012
import org.springframework.web.bind.MethodArgumentNotValidException;
1113
import org.springframework.web.bind.annotation.ExceptionHandler;
1214
import org.springframework.web.bind.annotation.RestControllerAdvice;
1315

16+
@Slf4j
1417
@RestControllerAdvice
1518
public class GlobalExceptionHandler {
1619

1720
@ExceptionHandler(CustomException.class)
1821
public ResponseEntity<ErrorResponse> handleCustomException(CustomException e) {
22+
log.warn(e.getMessage());
1923
ErrorCode errorCode = e.getErrorCode();
2024

2125
ErrorResponse response = new ErrorResponse(errorCode.getCode(), errorCode.getMessage());
@@ -24,6 +28,7 @@ public ResponseEntity<ErrorResponse> handleCustomException(CustomException e) {
2428

2529
@ExceptionHandler(Exception.class)
2630
public ResponseEntity<ErrorResponse> handleException(Exception e) {
31+
log.warn("handleException: {}", e.getMessage());
2732
CommonErrorCode errorCode = CommonErrorCode.INTERNAL_SERVER_ERROR;
2833

2934
ErrorResponse response = new ErrorResponse(errorCode.getCode(), errorCode.getMessage());
@@ -33,7 +38,7 @@ public ResponseEntity<ErrorResponse> handleException(Exception e) {
3338
@ExceptionHandler(MethodArgumentNotValidException.class)
3439
public ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(
3540
MethodArgumentNotValidException e) {
36-
41+
log.warn("MethodArgumentNotValidException: {}", e.getMessage());
3742
CommonErrorCode code = CommonErrorCode.BAD_REQUEST_DATA;
3843

3944
String message =
@@ -46,4 +51,14 @@ public ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(
4651

4752
return new ResponseEntity<>(response, code.getHttpStatus());
4853
}
54+
55+
@ExceptionHandler(HttpMessageNotReadableException.class)
56+
public ResponseEntity<ErrorResponse> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
57+
log.warn("HttpMessageNotReadableException: {}", e.getMessage());
58+
CommonErrorCode code = CommonErrorCode.INVALID_JSON_FORMAT;
59+
60+
ErrorResponse response = new ErrorResponse(code.getCode(), code.getMessage());
61+
62+
return new ResponseEntity<>(response, code.getHttpStatus());
63+
}
4964
}

0 commit comments

Comments
 (0)