From a7e3f31a1f01277b445e163fcc9b73db926aa9a2 Mon Sep 17 00:00:00 2001 From: jiseon Date: Sat, 21 Sep 2024 15:31:03 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20MaxUploadSizeExceededException=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20status=20code=20413=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dissonance/itit/common/exception/ErrorCode.java | 1 - .../common/exception/GlobalExceptionHandler.java | 13 +++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dissonance/itit/common/exception/ErrorCode.java b/src/main/java/com/dissonance/itit/common/exception/ErrorCode.java index 36dabbb..0ab6378 100644 --- a/src/main/java/com/dissonance/itit/common/exception/ErrorCode.java +++ b/src/main/java/com/dissonance/itit/common/exception/ErrorCode.java @@ -11,7 +11,6 @@ public enum ErrorCode { // 400 INVALID_PROVIDER(HttpStatus.BAD_REQUEST, "존재하지 않는 Provider입니다."), INVALID_FILE_TYPE(HttpStatus.BAD_REQUEST, "파일 형식은 이미지만 가능합니다."), - INVALID_FILE_SIZE(HttpStatus.BAD_REQUEST, "파일 용량은 10MB를 넘을 수 없습니다."), INVALID_DATE_FORMAT(HttpStatus.BAD_REQUEST, "날짜 변환에 실패했습니다."), INVALID_APPLE_TOKEN(HttpStatus.BAD_REQUEST, "유효하지 않는 Apple Token입니다."), INVALID_JSON_FORMAT(HttpStatus.BAD_REQUEST, "잘못된 JSON 형식입니다."), diff --git a/src/main/java/com/dissonance/itit/common/exception/GlobalExceptionHandler.java b/src/main/java/com/dissonance/itit/common/exception/GlobalExceptionHandler.java index d75f3c1..8ec0d84 100644 --- a/src/main/java/com/dissonance/itit/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/dissonance/itit/common/exception/GlobalExceptionHandler.java @@ -4,6 +4,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.multipart.MaxUploadSizeExceededException; import com.dissonance.itit.common.util.ApiResponse; @@ -13,7 +14,7 @@ @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(CustomException.class) - protected ResponseEntity handleCustomException(CustomException e) { + protected ResponseEntity> handleCustomException(CustomException e) { int statusCode = e.getErrorCode().getHttpStatus().value(); log.error("CustomException : {}", e.getMessage()); return new ResponseEntity<>(ApiResponse.error(statusCode, e.getMessage()), @@ -21,10 +22,18 @@ protected ResponseEntity handleCustomException(CustomException e) { } @ExceptionHandler(Exception.class) - public ResponseEntity handleAllException(final Exception e) { + public ResponseEntity> handleAllException(final Exception e) { int statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value(); log.error("handleAllException {}", e.getMessage()); return new ResponseEntity<>(ApiResponse.error(statusCode, e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR); } + + @ExceptionHandler(MaxUploadSizeExceededException.class) + public ResponseEntity> handleMaxSizeException(MaxUploadSizeExceededException e) { + int statusCode = e.getStatusCode().value(); + log.error("MaxUploadSizeExceededException {}", e.getMessage()); + return new ResponseEntity<>(ApiResponse.error(statusCode, e.getMessage()), + HttpStatus.PAYLOAD_TOO_LARGE); + } }