diff --git a/src/main/java/hsu/umc/server/apipayload/code/status/ErrorStatus.java b/src/main/java/hsu/umc/server/apipayload/code/status/ErrorStatus.java index de2f5b6..cf4a0ed 100644 --- a/src/main/java/hsu/umc/server/apipayload/code/status/ErrorStatus.java +++ b/src/main/java/hsu/umc/server/apipayload/code/status/ErrorStatus.java @@ -20,7 +20,8 @@ public enum ErrorStatus implements ErrorCode { INVALID_CREDENTIALS(HttpStatus.NOT_FOUND, "USER4002", "유저의 비밀번호가 맞지 않습니다."), //질문 관련 응답 QUESTION_NOT_FOUND(HttpStatus.NOT_FOUND, "QUESTION4001", "아이디에 해당하는 질문을 찾을 수 업습니다."), - ANSWER_NOT_FOUND(HttpStatus.NOT_FOUND, "ANSWER4001", "아이디에 해당하는 답변을 찾을 수 업습니다."); + ANSWER_NOT_FOUND(HttpStatus.NOT_FOUND, "ANSWER4001", "아이디에 해당하는 답변을 찾을 수 업습니다."), + _PAYLOAD_TOO_LARGE(HttpStatus.PAYLOAD_TOO_LARGE, "PAYLOAD4001","파일 크기가 허용된 최대 크기를 초과했습니다."); private final HttpStatus httpStatus; diff --git a/src/main/java/hsu/umc/server/apipayload/exception/ExceptionAdvice.java b/src/main/java/hsu/umc/server/apipayload/exception/ExceptionAdvice.java index d5505d6..3a6434f 100644 --- a/src/main/java/hsu/umc/server/apipayload/exception/ExceptionAdvice.java +++ b/src/main/java/hsu/umc/server/apipayload/exception/ExceptionAdvice.java @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.WebRequest; +import org.springframework.web.multipart.MaxUploadSizeExceededException; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import java.util.LinkedHashMap; @@ -119,4 +120,16 @@ private ResponseEntity handleExceptionInternalConstraint(Exception e, Er request ); } + + @Override + protected ResponseEntity handleExceptionInternal(Exception ex, @Nullable Object body, HttpHeaders headers, + HttpStatusCode status, WebRequest request) { + if (ex instanceof MaxUploadSizeExceededException) { + ErrorStatus errorStatus = ErrorStatus._PAYLOAD_TOO_LARGE; + ApiResponse customBody = ApiResponse.onFailure(errorStatus.getCode(), errorStatus.getMessage(), null); + return new ResponseEntity<>(customBody, headers, errorStatus.getHttpStatus()); + } + return super.handleExceptionInternal(ex, body, headers, status, request); + } + } \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index ef89b30..37746b5 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -16,6 +16,11 @@ spring: allowed-headers: "*" allow-credentials: true + servlet: + multipart: + max-file-size: 10MB + max-request-size: 20MB + cloud: aws: s3: diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 7caf06a..2f92b7d 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -17,6 +17,11 @@ spring: hbm2ddl: auto: update + servlet: + multipart: + max-file-size: 10MB + max-request-size: 10MB + cloud: aws: s3: