diff --git a/lime-api/src/main/java/com/programmers/lime/global/error/GlobalExceptionHandler.java b/lime-api/src/main/java/com/programmers/lime/global/error/GlobalExceptionHandler.java index 39f53590..e6535aba 100644 --- a/lime-api/src/main/java/com/programmers/lime/global/error/GlobalExceptionHandler.java +++ b/lime-api/src/main/java/com/programmers/lime/global/error/GlobalExceptionHandler.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.multipart.MultipartException; +import org.springframework.web.multipart.support.MissingServletRequestPartException; import com.programmers.lime.error.BusinessException; import com.programmers.lime.error.EntityNotFoundException; @@ -94,6 +95,15 @@ public ResponseEntity handleMultipartException(final MultipartExc return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); } + @ExceptionHandler(MissingServletRequestPartException.class) + public ResponseEntity handleMissingServletRequestPartException( + final MissingServletRequestPartException e) { + log.info("MissingServletRequestPartException", e); + final ErrorResponse response = ErrorResponse.from(ErrorCode.MISSING_REQUEST_IMAGE); + + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + @ExceptionHandler(HttpMessageNotReadableException.class) public ResponseEntity handleHttpMessageNotReadableException( final HttpMessageNotReadableException e) { diff --git a/lime-common/src/main/java/com/programmers/lime/error/ErrorCode.java b/lime-common/src/main/java/com/programmers/lime/error/ErrorCode.java index c18350b9..83eca605 100644 --- a/lime-common/src/main/java/com/programmers/lime/error/ErrorCode.java +++ b/lime-common/src/main/java/com/programmers/lime/error/ErrorCode.java @@ -36,6 +36,7 @@ public enum ErrorCode { INVALID_ACCESSOR("COMMON_020", "잘못된 Accessor 입니다."), UNSUPPORTED_IMAGE_TYPE("COMMON_021", "업로드 할 수 있는 이미지 확장자가 아닙니다."), NOT_CONVERTIBLE_IMAGE("COMMON_022", "이미지 변환에 실패했습니다."), + MISSING_REQUEST_IMAGE("COMMON_023", "하나 이상의 이미지를 업로드 해야합니다"), // Member MEMBER_LOGIN_FAIL("MEMBER_001", "로그인 정보가 잘못 되었습니다."),