@@ -5,6 +5,7 @@ import mu.KotlinLogging
55import org.springframework.http.ResponseEntity
66import org.springframework.http.converter.HttpMessageNotReadableException
77import org.springframework.validation.BindException
8+ import org.springframework.web.HttpRequestMethodNotSupportedException
89import org.springframework.web.bind.MethodArgumentNotValidException
910import org.springframework.web.bind.annotation.ExceptionHandler
1011import org.springframework.web.bind.annotation.RestControllerAdvice
@@ -99,6 +100,24 @@ class GlobalExceptionHandler {
99100 return ResponseEntity (error, commonErrorCode.getHttpStatus())
100101 }
101102
103+ /* *
104+ * 잘못된 HTTP 메서드로 인한 HttpRequestMethodNotSupportedException를 처리합니다.
105+ */
106+ @ExceptionHandler(HttpRequestMethodNotSupportedException ::class )
107+ protected fun handleHttpRequestMethodNotSupportedException (ex : HttpRequestMethodNotSupportedException ): ResponseEntity <ErrorResponse > {
108+ val commonErrorCode = CommonErrorCode .METHOD_NOT_ALLOWED
109+
110+ log.warn { " HTTP method not supported: ${ex.method} for ${ex.supportedHttpMethods?.joinToString()} " }
111+
112+ val error = ErrorResponse .builder()
113+ .status(commonErrorCode.getHttpStatus().value())
114+ .message(" HTTP method '${ex.method} ' not supported for this endpoint. Supported methods: ${ex.supportedHttpMethods?.joinToString()} " )
115+ .code(commonErrorCode.getCode())
116+ .build()
117+
118+ return ResponseEntity (error, commonErrorCode.getHttpStatus())
119+ }
120+
102121
103122 /* *
104123 * 메서드 파라미터 검증 실패(@RequestParam, @PathVariable 등)
0 commit comments