Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api: ✏️ HttpRequestMethodNotSupportedException 전역 예외 설정 #147

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,21 @@ protected ResponseEntity<ErrorResponse> 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' 내에 데이터 값이 유효하지 않은 경우
*
Expand Down
Loading