|
5 | 5 | import org.springframework.http.ResponseEntity; |
6 | 6 | import org.springframework.http.converter.HttpMessageNotReadableException; |
7 | 7 | import org.springframework.validation.FieldError; |
| 8 | +import org.springframework.web.HttpRequestMethodNotSupportedException; |
8 | 9 | import org.springframework.web.bind.MethodArgumentNotValidException; |
9 | 10 | import org.springframework.web.bind.MissingServletRequestParameterException; |
10 | 11 | import org.springframework.web.bind.annotation.ExceptionHandler; |
@@ -54,6 +55,25 @@ public ResponseEntity<ErrorResponse> handleHttpMessageNotReadable(HttpMessageNot |
54 | 55 | .body(ErrorResponse.of(ErrorCode.INVALID_FORMAT, ErrorCode.INVALID_FORMAT.getMessage())); |
55 | 56 | } |
56 | 57 |
|
| 58 | + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) |
| 59 | + public ResponseEntity<ErrorResponse> handleMethodNotSupported(HttpRequestMethodNotSupportedException e) { |
| 60 | + |
| 61 | + String method = e.getMethod(); |
| 62 | + String supported = (e.getSupportedMethods() != null) |
| 63 | + ? String.join(", ", e.getSupportedMethods()) |
| 64 | + : "N/A"; |
| 65 | + |
| 66 | + String message = String.format( |
| 67 | + "요청 메서드 '%s' 는 지원되지 않습니다. 가능한 메서드: [%s]", |
| 68 | + method, supported |
| 69 | + ); |
| 70 | + |
| 71 | + return ResponseEntity |
| 72 | + .status(ErrorCode.METHOD_NOT_ALLOWED.getStatus()) |
| 73 | + .body(ErrorResponse.of(ErrorCode.METHOD_NOT_ALLOWED, message)); |
| 74 | + } |
| 75 | + |
| 76 | + |
57 | 77 | @ExceptionHandler(BusinessException.class) |
58 | 78 | public ResponseEntity<ErrorResponse> handleBusinessException(BusinessException e) { |
59 | 79 | ErrorCode errorCode = e.getErrorCode(); |
|
0 commit comments