Skip to content

Commit

Permalink
feat: DateTimeParseException handler 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
abc5259 committed Oct 17, 2024
1 parent c850028 commit dd8a75b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", "알 수 없는 에러")
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,18 @@ protected ResponseEntity<ResponseDto<?>> handleMethodArgumentNotValidException(
return ResponseDto.fail(errorCode);
}

@ExceptionHandler(DateTimeParseException.class)
protected ResponseEntity<ResponseDto<?>> 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<ResponseDto<?>> handleBusinessException(
final Exception e,
Expand Down

0 comments on commit dd8a75b

Please sign in to comment.