diff --git a/src/main/java/igoMoney/BE/common/exception/CustomExceptionHandler.java b/src/main/java/igoMoney/BE/common/exception/CustomExceptionHandler.java index 2e98592..9f8df7a 100644 --- a/src/main/java/igoMoney/BE/common/exception/CustomExceptionHandler.java +++ b/src/main/java/igoMoney/BE/common/exception/CustomExceptionHandler.java @@ -1,6 +1,7 @@ package igoMoney.BE.common.exception; import lombok.extern.slf4j.Slf4j; +import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.BindException; @@ -33,5 +34,11 @@ protected ResponseEntity handleBindException(BindException e) { log.info(fieldError.toString()); return ErrorResponse.toResponseEntity(HttpStatus.BAD_REQUEST, fieldError); } + + @ExceptionHandler(FileSizeLimitExceededException.class) + public ResponseEntity handleSizeLimitExceededException(FileSizeLimitExceededException ex) { + log.info("SizeLimitExceededException :: " + ex.getLocalizedMessage()); + return ErrorResponse.toResponseEntity(new CustomException(ErrorCode.IMAGE_SIZE_EXCEEDED)); + } } diff --git a/src/main/java/igoMoney/BE/common/exception/ErrorCode.java b/src/main/java/igoMoney/BE/common/exception/ErrorCode.java index 19c5c5d..435566d 100644 --- a/src/main/java/igoMoney/BE/common/exception/ErrorCode.java +++ b/src/main/java/igoMoney/BE/common/exception/ErrorCode.java @@ -40,7 +40,8 @@ public enum ErrorCode { NOT_FOUND_NOTIFICATION(HttpStatus.NOT_FOUND, "해당 Notification을 찾을 수 없습니다."), // 이미지 예외 - SHOULD_EXIST_IMAGE(HttpStatus.BAD_REQUEST, "이미지가 존재하지 않습니다."); + SHOULD_EXIST_IMAGE(HttpStatus.BAD_REQUEST, "이미지가 존재하지 않습니다."), + IMAGE_SIZE_EXCEEDED(HttpStatus.BAD_REQUEST, "이미지 파일이 너무 큽니다."); private final HttpStatus httpStatus; diff --git a/src/main/java/igoMoney/BE/common/exception/ErrorResponse.java b/src/main/java/igoMoney/BE/common/exception/ErrorResponse.java index ec4af43..7a42029 100644 --- a/src/main/java/igoMoney/BE/common/exception/ErrorResponse.java +++ b/src/main/java/igoMoney/BE/common/exception/ErrorResponse.java @@ -14,6 +14,7 @@ @Builder public class ErrorResponse { + @Builder.Default private LocalDateTime timestamp = LocalDateTime.now(); private final int status; private final String error; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 71b47a3..a438bec 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -35,6 +35,10 @@ spring: stack: auto : false + servlet: + multipart: + max-file-size: 2MB + max-request-size: 10MB security: oauth2: