Skip to content

Commit

Permalink
Merge pull request #210 from side-peek/feat/#209-handle-HttpRequestMe…
Browse files Browse the repository at this point in the history
…thodNotSupportedException

HttpRequestMethodNotSupportedException 핸들러 구현
  • Loading branch information
Sehee-Lee-01 authored Mar 20, 2024
2 parents 7abca59 + 677252c commit ad18d45
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.security.access.AccessDeniedException;
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;
Expand All @@ -25,6 +27,18 @@ public class GlobalExceptionHandler {

private final SlackClient slackClient;

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<ErrorResponse> handleHttpRequestMethodNotSupportedException(
HttpRequestMethodNotSupportedException e) {
ErrorResponse errorResponse = ErrorResponse.of(HttpStatus.METHOD_NOT_ALLOWED,
"해당 요청에서 " + e.getMethod() + " Method는 지원하지 않습니다.");
log.debug(e.getMessage(), e.fillInStackTrace());

return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED)
.allow(e.getSupportedHttpMethods().toArray(new HttpMethod[0]))
.body(errorResponse);
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<List<ErrorResponse>> handleMethodArgumentNotValidException(
MethodArgumentNotValidException e) {
Expand Down

0 comments on commit ad18d45

Please sign in to comment.