Java Code Examples for org.springframework.http.converter.HttpMessageNotReadableException#getMessage()
The following examples show how to use
org.springframework.http.converter.HttpMessageNotReadableException#getMessage() .
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: ExceptionHandlerControllerAdvice.java From OpenLRW with Educational Community License v2.0 | 6 votes |
@ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public MessageResponse handleHttpMessageNotReadableException(HttpServletRequest request, HttpMessageNotReadableException e) { if (e.getCause() instanceof UnrecognizedPropertyException) { return handleUnrecognizedPropertyException(request, (UnrecognizedPropertyException)e.getCause()); } else { MessageResponse response; if (e.getCause() instanceof JsonProcessingException) { JsonProcessingException jpe = (JsonProcessingException)e.getCause(); response = new MessageResponse(HttpStatus.BAD_REQUEST, buildDate(), request, jpe.getOriginalMessage()); } else { response = new MessageResponse(HttpStatus.BAD_REQUEST, buildDate(), request, e.getMessage()); } log(e, response); return response; } }
Example 2
Source File: NakadiProblemExceptionHandler.java From nakadi with MIT License | 6 votes |
@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 3
Source File: GlobalExceptionHandler.java From Spring-Boot-Book with Apache License 2.0 | 5 votes |
/** * 400 - Bad Request */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(HttpMessageNotReadableException.class) public String handleHttpMessageNotReadableException(HttpMessageNotReadableException e, Model model) { logger.error("参数解析失败", e); String message = "【参数解析失败】" + e.getMessage(); model.addAttribute("message", message); model.addAttribute("code", 400); return viewName; }
Example 4
Source File: GlobalExceptionHandler.java From Spring-Boot-Book with Apache License 2.0 | 5 votes |
/** * 400 - Bad Request */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(HttpMessageNotReadableException.class) public String handleHttpMessageNotReadableException(HttpMessageNotReadableException e, Model model) { logger.error("参数解析失败", e); String message = "【参数解析失败】" + e.getMessage(); model.addAttribute("message", message); model.addAttribute("code", 400); return viewName; }
Example 5
Source File: GlobalExceptionHand.java From spring-boot-shiro with Apache License 2.0 | 5 votes |
/** * 400 - Bad Request */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(HttpMessageNotReadableException.class) public Response handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { String msg = e.getMessage(); log.error("参数解析失败:", e); return new Response().failure(msg); }
Example 6
Source File: GlobalExceptionHandler.java From SENS with GNU General Public License v3.0 | 5 votes |
/** * 400 - Bad Request */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(HttpMessageNotReadableException.class) public String handleHttpMessageNotReadableException(HttpMessageNotReadableException e, Model model) { log.error("参数解析失败", e); String message = "【参数解析失败】" + e.getMessage(); model.addAttribute("message", message); model.addAttribute("code", 400); return viewName; }
Example 7
Source File: GlobalControllerAdvice.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@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 8
Source File: GlobalControllerAdvice.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@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 9
Source File: GlobalControllerAdvice.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@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 10
Source File: ExceptionProcessor.java From personal_book_library_web_project with MIT License | 5 votes |
@ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody public ServiceExceptionDetails processHttpMessageNotReadableException(HttpMessageNotReadableException exception) { String detailedErrorMessage = exception.getMessage(); return new ServiceExceptionDetails("", detailedErrorMessage, ""); }
Example 11
Source File: BaseController.java From ankush with GNU Lesser General Public License v3.0 | 5 votes |
/** * Exception handler. * * @param e the e * @return the response entity */ @ExceptionHandler(HttpMessageNotReadableException.class) @ResponseBody public ResponseEntity<String> exceptionHandler( HttpMessageNotReadableException e) { log.error("Invalid request body", e); return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST); }
Example 12
Source File: RestController.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(BAD_REQUEST) public ErrorMessageResponse handleHttpMessageNotReadableException( HttpMessageNotReadableException e) { LOG.error("", e); return new ErrorMessageResponse(new ErrorMessage(e.getMessage())); }