Skip to content

Commit

Permalink
feat: HttpMessageNotReadableException handler 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
abc5259 committed Oct 17, 2024
1 parent dd8a75b commit 1c6a4c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum CommonErrorCode implements ErrorCodeInterface {

DUPLICATION(HttpStatus.CONFLICT, "COMMON_DUPLICATION", "중복된 리소스가 존재합니다."),
VALIDATION_ERROR(HttpStatus.BAD_REQUEST, "VALIDATION_ERROR", "유효성 검사 실패했습니다."),
DATA_TIME_PARSE_ERROR(HttpStatus.BAD_REQUEST, "DATA_TIME_PARSE_ERROR", "요청된 시간을 파싱할 수 없습니다."),
INVALID_REQUEST(HttpStatus.BAD_REQUEST, "INVALID_REQUEST", "요청 형식에 맞지 않는 요청입니다. api 문서를 다시 확인해 주세요."),

INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "INTERNAL_SERVER_ERROR", "알 수 없는 에러")
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand Down Expand Up @@ -56,15 +57,15 @@ protected ResponseEntity<ResponseDto<?>> handleMethodArgumentNotValidException(
return ResponseDto.fail(errorCode);
}

@ExceptionHandler(DateTimeParseException.class)
protected ResponseEntity<ResponseDto<?>> handleDateTimeParseException(
final DateTimeParseException e,
@ExceptionHandler(HttpMessageNotReadableException.class)
protected ResponseEntity<ResponseDto<?>> handleHttpMessageNotReadableException(
final HttpMessageNotReadableException e,
final HttpServletRequest request
) {
ErrorCode errorCode = CommonErrorCode.DATA_TIME_PARSE_ERROR.toErrorCode();
ErrorCode errorCode = CommonErrorCode.INVALID_REQUEST.toErrorCode();
errorCode.appendMessage(e.getMessage());

log.info("DateTimeParseException: {} {}", e.getMessage(), request.getRequestURL(), e);
log.info("HttpMessageNotReadableException: {} {}", e.getMessage(), request.getRequestURL(), e);
return ResponseDto.fail(errorCode);
}

Expand Down

0 comments on commit 1c6a4c3

Please sign in to comment.