Skip to content

Commit e060fe1

Browse files
committed
feat : 파일용량 예외처리 추가
1 parent 1e1072c commit e060fe1

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/main/java/com/grepp/teamnotfound/infra/error/exception/advice/GlobalExceptionHandler.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.Objects;
2222

2323
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
24+
import org.springframework.web.multipart.MaxUploadSizeExceededException;
25+
import org.springframework.web.multipart.MultipartException;
2426

2527
@Slf4j
2628
@RestControllerAdvice
@@ -93,4 +95,28 @@ public ResponseEntity<ErrorResponse> handleException(Exception e) {
9395
.status(HttpStatus.INTERNAL_SERVER_ERROR)
9496
.body(response);
9597
}
98+
99+
@ExceptionHandler(MaxUploadSizeExceededException.class)
100+
public ResponseEntity<ErrorResponse> handleMaxSizeException(MaxUploadSizeExceededException e) {
101+
return ResponseEntity
102+
.status(HttpStatus.PAYLOAD_TOO_LARGE)
103+
.body(new ErrorResponse(
104+
HttpStatus.PAYLOAD_TOO_LARGE.value(),
105+
"PAYLOAD_TOO_LARGE",
106+
"파일 크기가 너무 큽니다. 최대 5MB 까지 업로드할 수 있습니다.",
107+
LocalDateTime.now()
108+
));
109+
}
110+
111+
@ExceptionHandler(MultipartException.class)
112+
public ResponseEntity<ErrorResponse> handleMultipartException(MultipartException ex) {
113+
return ResponseEntity
114+
.status(HttpStatus.BAD_REQUEST)
115+
.body(new ErrorResponse(
116+
HttpStatus.BAD_REQUEST.value(),
117+
"BAD_REQUEST",
118+
"파일 업로드 중 오류가 발생했습니다. 파일이나 요청의 형식을 확인해주세요.",
119+
LocalDateTime.now()
120+
));
121+
}
96122
}

src/main/resources/application.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ springdoc.swagger-ui.try-it-out-enabled=true
7777
# bucket
7878
google.cloud.storage.bucket=mungnote-storage
7979
image.clean.period-days=30
80-
80+
spring.servlet.multipart.max-file-size=5MB
81+
spring.servlet.multipart.max-request-size=10MB
8182

8283

8384
# OAuth2.0

0 commit comments

Comments
 (0)