diff --git a/src/main/java/com/dnd/snappy/common/error/CommonErrorCode.java b/src/main/java/com/dnd/snappy/common/error/CommonErrorCode.java index 0ee8c11..875266a 100644 --- a/src/main/java/com/dnd/snappy/common/error/CommonErrorCode.java +++ b/src/main/java/com/dnd/snappy/common/error/CommonErrorCode.java @@ -9,10 +9,10 @@ public enum CommonErrorCode implements ErrorCodeInterface { BAD_REQUEST(HttpStatus.BAD_REQUEST, "COMMON_BAD_REQUEST", "요청을 이해할 수 없거나 필수 매개변수가 누락되었습니다."), NOT_FOUND(HttpStatus.NOT_FOUND, "COMMON_NOT_FOUND", "요청된 리소스를 찾을 수 없습니다."), - - + DUPLICATION(HttpStatus.CONFLICT, "COMMON_DUPLICATION", "중복된 리소스가 존재합니다."), VALIDATION_ERROR(HttpStatus.BAD_REQUEST, "VALIDATION_ERROR", "유효성 검사 실패했습니다."), + DATA_TIME_PARSE_ERROR(HttpStatus.BAD_REQUEST, "DATA_TIME_PARSE_ERROR", "요청된 시간을 파싱할 수 없습니다."), INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "INTERNAL_SERVER_ERROR", "알 수 없는 에러") ; diff --git a/src/main/java/com/dnd/snappy/common/error/GlobalExceptionHandler.java b/src/main/java/com/dnd/snappy/common/error/GlobalExceptionHandler.java index c163cdb..70c5b7e 100644 --- a/src/main/java/com/dnd/snappy/common/error/GlobalExceptionHandler.java +++ b/src/main/java/com/dnd/snappy/common/error/GlobalExceptionHandler.java @@ -4,6 +4,7 @@ import com.dnd.snappy.common.error.exception.BusinessException; import com.dnd.snappy.common.error.exception.ImageException; import jakarta.servlet.http.HttpServletRequest; +import java.time.format.DateTimeParseException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; @@ -55,6 +56,18 @@ protected ResponseEntity> handleMethodArgumentNotValidException( return ResponseDto.fail(errorCode); } + @ExceptionHandler(DateTimeParseException.class) + protected ResponseEntity> handleDateTimeParseException( + final DateTimeParseException e, + final HttpServletRequest request + ) { + ErrorCode errorCode = CommonErrorCode.DATA_TIME_PARSE_ERROR.toErrorCode(); + errorCode.appendMessage(e.getMessage()); + + log.info("DateTimeParseException: {} {}", e.getMessage(), request.getRequestURL(), e); + return ResponseDto.fail(errorCode); + } + @ExceptionHandler(Exception.class) protected ResponseEntity> handleBusinessException( final Exception e,