Skip to content

Commit

Permalink
♻️ hotfix(api): add Method not support exception (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
seonghun-dev authored Aug 24, 2023
1 parent a1dcaeb commit 6064214
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,6 +64,21 @@ protected ResponseEntity<ErrorResponseDto> handleMethodArgumentNotValidException
.body(errorResponseDto);
}

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
protected ResponseEntity<ErrorResponseDto> 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<ErrorResponseDto> handleInternalException(
final Exception e,
Expand Down

0 comments on commit 6064214

Please sign in to comment.