From d785f4594fbd4eb430a297f9fb85ee62b6f85036 Mon Sep 17 00:00:00 2001 From: BK Date: Wed, 15 Nov 2023 23:55:56 +0900 Subject: [PATCH] =?UTF-8?q?Chore:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=ED=81=AC=EA=B8=B0=20=EC=A0=9C?= =?UTF-8?q?=ED=95=9C=20=EB=B3=80=EA=B2=BD=20&=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EB=B0=98=ED=99=98=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BE/common/exception/CustomExceptionHandler.java | 7 +++++++ src/main/java/igoMoney/BE/common/exception/ErrorCode.java | 3 ++- .../java/igoMoney/BE/common/exception/ErrorResponse.java | 1 + src/main/resources/application.yml | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) 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: