@ExceptionHandler(HttpRequestMethodNotSupportedException.class) public ResponseEntity<OAuth2Exception> handleMethodNotSupportedException(HttpRequestMethodNotSupportedException e) throws Exception { logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage()); ResponseEntity<OAuth2Exception> result = exceptionTranslator.translate(e); if (HttpMethod.POST.matches(e.getMethod())) { OAuth2Exception cause = new OAuth2Exception("Parameters must be passed in the body of the request", result.getBody().getCause()) { public String getOAuth2ErrorCode() { return "query_string_not_allowed"; } public int getHttpErrorCode() { return NOT_ACCEPTABLE.value(); } }; result = new ResponseEntity<>(cause, result.getHeaders(), NOT_ACCEPTABLE); } return result; }
public CustomOAuth2Exception(ErrorResponse errorResponse, OAuth2Exception ex) { super(ex.getMessage(), ex.getCause()); this.errorResponse = errorResponse; }