|
8 | 8 | import org.layer.common.exception.ExceptionType; |
9 | 9 | import org.layer.discord.notifier.ErrorEvent; |
10 | 10 | import org.springframework.context.ApplicationEventPublisher; |
| 11 | +import org.springframework.core.convert.ConversionFailedException; |
11 | 12 | import org.springframework.http.HttpStatus; |
12 | 13 | import org.springframework.http.ResponseEntity; |
13 | 14 | import org.springframework.http.converter.HttpMessageNotReadableException; |
|
16 | 17 | import org.springframework.web.bind.MissingServletRequestParameterException; |
17 | 18 | import org.springframework.web.bind.annotation.ExceptionHandler; |
18 | 19 | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| 20 | +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; |
19 | 21 | import org.springframework.web.servlet.resource.NoResourceFoundException; |
20 | 22 |
|
21 | 23 | import lombok.RequiredArgsConstructor; |
@@ -81,4 +83,23 @@ public ResponseEntity<ExceptionResponse> handleMissingServletRequestParameterExc |
81 | 83 | return ResponseEntity.status(HttpStatus.BAD_REQUEST) |
82 | 84 | .body(ExceptionResponse.of(HttpStatus.BAD_REQUEST.name(), "유효하지 않은 값.")); |
83 | 85 | } |
| 86 | + |
| 87 | + @ExceptionHandler(MethodArgumentTypeMismatchException.class) |
| 88 | + public ResponseEntity<ExceptionResponse> handleMethodArgumentTypeMismatchException( |
| 89 | + MethodArgumentTypeMismatchException e) { |
| 90 | + log.warn(String.format(LOG_FORMAT, e.getMessage()), e); |
| 91 | + String paramName = e.getName(); |
| 92 | + String invalidValue = e.getValue() != null ? e.getValue().toString() : "null"; |
| 93 | + return ResponseEntity.status(HttpStatus.BAD_REQUEST) |
| 94 | + .body(ExceptionResponse.of(HttpStatus.BAD_REQUEST.name(), |
| 95 | + String.format("파라미터 '%s'의 값 '%s'은(는) 유효하지 않습니다.", paramName, invalidValue))); |
| 96 | + } |
| 97 | + |
| 98 | + @ExceptionHandler(ConversionFailedException.class) |
| 99 | + public ResponseEntity<ExceptionResponse> handleConversionFailedException(ConversionFailedException e) { |
| 100 | + log.warn(String.format(LOG_FORMAT, e.getMessage()), e); |
| 101 | + return ResponseEntity.status(HttpStatus.BAD_REQUEST) |
| 102 | + .body(ExceptionResponse.of(HttpStatus.BAD_REQUEST.name(), "요청 파라미터의 형식이 잘못되었습니다.")); |
| 103 | + } |
| 104 | + |
84 | 105 | } |
0 commit comments