From 606421494d86c26f5d495a47943d37c0e474ff8e Mon Sep 17 00:00:00 2001 From: Jung Seonghun <80201773+seonghun-dev@users.noreply.github.com> Date: Thu, 24 Aug 2023 17:24:48 +0900 Subject: [PATCH] :recycle: hotfix(api): add Method not support exception (#304) --- .../common/error/GlobalExceptionHandler.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/streetdrop-api/src/main/java/com/depromeet/common/error/GlobalExceptionHandler.java b/backend/streetdrop-api/src/main/java/com/depromeet/common/error/GlobalExceptionHandler.java index 77835af1..ae3b9ba2 100644 --- a/backend/streetdrop-api/src/main/java/com/depromeet/common/error/GlobalExceptionHandler.java +++ b/backend/streetdrop-api/src/main/java/com/depromeet/common/error/GlobalExceptionHandler.java @@ -11,6 +11,7 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.ResponseEntity; +import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -63,6 +64,21 @@ protected ResponseEntity handleMethodArgumentNotValidException .body(errorResponseDto); } + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + protected ResponseEntity handleMethodNotSupportException( + final HttpRequestMethodNotSupportedException e + ) { + ErrorResponseDto errorResponseDto = ErrorResponseDto.builder() + .code(ErrorCode.METHOD_NOT_ALLOWED.getCode()) + .status(ErrorCode.METHOD_NOT_ALLOWED.getStatus().value()) + .error(ErrorCode.METHOD_NOT_ALLOWED.getStatus().name()) + .message(e.getMessage()).build(); + + return ResponseEntity + .status(ErrorCode.METHOD_NOT_ALLOWED.getStatus().value()) + .body(errorResponseDto); + } + @ExceptionHandler(value = {Exception.class, RuntimeException.class, SQLException.class, DataIntegrityViolationException.class}) protected ResponseEntity handleInternalException( final Exception e,