Skip to content

Commit

Permalink
Chore: 이미지 업로드 크기 제한 변경 & 에러 메세지 반환 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
pingowl committed Nov 15, 2023
1 parent 452af80 commit d785f45
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,5 +34,11 @@ protected ResponseEntity<ErrorResponse> handleBindException(BindException e) {
log.info(fieldError.toString());
return ErrorResponse.toResponseEntity(HttpStatus.BAD_REQUEST, fieldError);
}

@ExceptionHandler(FileSizeLimitExceededException.class)
public ResponseEntity<ErrorResponse> handleSizeLimitExceededException(FileSizeLimitExceededException ex) {
log.info("SizeLimitExceededException :: " + ex.getLocalizedMessage());
return ErrorResponse.toResponseEntity(new CustomException(ErrorCode.IMAGE_SIZE_EXCEEDED));
}
}

3 changes: 2 additions & 1 deletion src/main/java/igoMoney/BE/common/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@Builder
public class ErrorResponse {

@Builder.Default
private LocalDateTime timestamp = LocalDateTime.now();
private final int status;
private final String error;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ spring:
stack:
auto : false

servlet:
multipart:
max-file-size: 2MB
max-request-size: 10MB

security:
oauth2:
Expand Down

0 comments on commit d785f45

Please sign in to comment.