Skip to content

Commit

Permalink
refactor: MaxUploadSizeExceededException 응답 status code 413으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
kikingki committed Sep 21, 2024
1 parent ee71088 commit a7e3f31
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public enum ErrorCode {
// 400
INVALID_PROVIDER(HttpStatus.BAD_REQUEST, "존재하지 않는 Provider입니다."),
INVALID_FILE_TYPE(HttpStatus.BAD_REQUEST, "파일 형식은 이미지만 가능합니다."),
INVALID_FILE_SIZE(HttpStatus.BAD_REQUEST, "파일 용량은 10MB를 넘을 수 없습니다."),
INVALID_DATE_FORMAT(HttpStatus.BAD_REQUEST, "날짜 변환에 실패했습니다."),
INVALID_APPLE_TOKEN(HttpStatus.BAD_REQUEST, "유효하지 않는 Apple Token입니다."),
INVALID_JSON_FORMAT(HttpStatus.BAD_REQUEST, "잘못된 JSON 형식입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

import com.dissonance.itit.common.util.ApiResponse;

Expand All @@ -13,18 +14,26 @@
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(CustomException.class)
protected ResponseEntity<?> handleCustomException(CustomException e) {
protected ResponseEntity<ApiResponse<?>> handleCustomException(CustomException e) {
int statusCode = e.getErrorCode().getHttpStatus().value();
log.error("CustomException : {}", e.getMessage());
return new ResponseEntity<>(ApiResponse.error(statusCode, e.getMessage()),
e.getErrorCode().getHttpStatus());
}

@ExceptionHandler(Exception.class)
public ResponseEntity<?> handleAllException(final Exception e) {
public ResponseEntity<ApiResponse<?>> handleAllException(final Exception e) {
int statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
log.error("handleAllException {}", e.getMessage());
return new ResponseEntity<>(ApiResponse.error(statusCode, e.getMessage()),
HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(MaxUploadSizeExceededException.class)
public ResponseEntity<ApiResponse<?>> handleMaxSizeException(MaxUploadSizeExceededException e) {
int statusCode = e.getStatusCode().value();
log.error("MaxUploadSizeExceededException {}", e.getMessage());
return new ResponseEntity<>(ApiResponse.error(statusCode, e.getMessage()),
HttpStatus.PAYLOAD_TOO_LARGE);
}
}

0 comments on commit a7e3f31

Please sign in to comment.