File tree Expand file tree Collapse file tree
java/com/grepp/teamnotfound/infra/error/exception/advice Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121import java .util .Objects ;
2222
2323import 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+ "파일 크기가 너무 큽니다. 최대 3MB 까지 업로드할 수 있습니다." ,
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}
Original file line number Diff line number Diff line change @@ -77,7 +77,8 @@ springdoc.swagger-ui.try-it-out-enabled=true
7777# bucket
7878google.cloud.storage.bucket =mungnote-storage
7979image.clean.period-days =30
80-
80+ spring.servlet.multipart.max-file-size =3MB
81+ spring.servlet.multipart.max-request-size =20MB
8182
8283
8384# OAuth2.0
You can’t perform that action at this time.
0 commit comments