From b88d70c1ebe8cf0230ac0e36e4c702e22b019557 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Thu, 8 Aug 2024 01:38:52 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20http=20not=20support=20method=20exceptio?= =?UTF-8?q?n=20=ED=95=B8=EB=93=A4=EB=9F=AC=EC=97=90=20=EB=B0=98=EC=98=81?= =?UTF-8?q?=20(#147)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/handler/GlobalExceptionHandler.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/common/response/handler/GlobalExceptionHandler.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/common/response/handler/GlobalExceptionHandler.java index 3475651ca..7bb06c056 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/common/response/handler/GlobalExceptionHandler.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/common/response/handler/GlobalExceptionHandler.java @@ -19,6 +19,7 @@ import org.springframework.http.converter.HttpMessageNotWritableException; import org.springframework.security.access.AccessDeniedException; import org.springframework.validation.BindingResult; +import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingRequestHeaderException; import org.springframework.web.bind.MissingServletRequestParameterException; @@ -55,6 +56,21 @@ protected ResponseEntity handleGlobalErrorException(GlobalErrorEx return ResponseEntity.status(e.getBaseErrorCode().causedBy().statusCode().getCode()).body(response); } + /** + * API 호출 시 'Method' 내에 데이터 값이 유효하지 않은 경우 + * + * @see HttpRequestMethodNotSupportedException + */ + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + @JsonView(CustomJsonView.Common.class) + protected ErrorResponse handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { + log.warn("handleHttpRequestMethodNotSupportedException : {}", e.getMessage()); + String code = String.valueOf(StatusCode.BAD_REQUEST.getCode() * 10 + ReasonCode.INVALID_REQUEST.getCode()); + + return ErrorResponse.of(code, e.getMessage()); + } + /** * API 호출 시 'Header' 내에 데이터 값이 유효하지 않은 경우 *