Java Code Examples for org.springframework.http.converter.HttpMessageNotReadableException#getMostSpecificCause()

The following examples show how to use org.springframework.http.converter.HttpMessageNotReadableException#getMostSpecificCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NakadiProblemExceptionHandler.java    From nakadi with MIT License 6 votes vote down vote up
@Override
@ExceptionHandler
public ResponseEntity<Problem> handleMessageNotReadableException(final HttpMessageNotReadableException exception,
                                                                 final NativeWebRequest request) {
    /*
    Unwrap nested JsonMappingException because the enclosing HttpMessageNotReadableException adds some ugly, Java
    class and stacktrace like information.
     */
    final Throwable mostSpecificCause = exception.getMostSpecificCause();
    final String message;
    if (mostSpecificCause instanceof JsonMappingException) {
        message = mostSpecificCause.getMessage();
    } else {
        message = exception.getMessage();
    }
    return create(Problem.valueOf(BAD_REQUEST, message), request);
}
 
Example 2
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public ResponseEntity<ErrorMessage> handleHttpMessageNotReadable(HttpMessageNotReadableException ex) {
	Throwable mostSpecificCause = ex.getMostSpecificCause();
	ErrorMessage errorMessage;
	if (mostSpecificCause != null) {
		String exceptionName = mostSpecificCause.getClass().getName();
		String message = mostSpecificCause.getMessage();
		errorMessage = new ErrorMessage(exceptionName, message);
	}
	else {
		errorMessage = new ErrorMessage(ex.getMessage());
	}
	return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST);
}
 
Example 3
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public ResponseEntity<ErrorMessage> handleHttpMessageNotReadable(HttpMessageNotReadableException ex) {
	Throwable mostSpecificCause = ex.getMostSpecificCause();
	ErrorMessage errorMessage;
	if (mostSpecificCause != null) {
		String exceptionName = mostSpecificCause.getClass().getName();
		String message = mostSpecificCause.getMessage();
		errorMessage = new ErrorMessage(exceptionName, message);
	}
	else {
		errorMessage = new ErrorMessage(ex.getMessage());
	}
	return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST);
}
 
Example 4
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public ResponseEntity<ErrorMessage> handleHttpMessageNotReadable(HttpMessageNotReadableException ex) {
	Throwable mostSpecificCause = ex.getMostSpecificCause();
	ErrorMessage errorMessage;
	if (mostSpecificCause != null) {
		String exceptionName = mostSpecificCause.getClass().getName();
		String message = mostSpecificCause.getMessage();
		errorMessage = new ErrorMessage(exceptionName, message);
	}
	else {
		errorMessage = new ErrorMessage(ex.getMessage());
	}
	return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST);
}