@ExceptionHandler(HttpMessageNotReadableException.class) public void messageNotReadableException( HttpMessageNotReadableException exception, HttpServletRequest request, HttpServletResponse response) throws IOException { response.sendError(400, exception.getMessage()); }
@ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public R handleError(HttpMessageNotReadableException e) { log.error("消息不能读取:{}", e.getMessage()); return R.fail(ResultCode.MSG_NOT_READABLE, e.getMessage()); }
/** * 参数解析异常 * * @param e 异常信息 * @return */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(HttpMessageNotReadableException.class) public BaseMessage handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { return pubTools.genNoMsg(StatusCode.BAD_REQUEST, e.getMessage()); }
@ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(value = HttpStatus.BAD_REQUEST) public Object handHttpMessageNotReadableException(HttpMessageNotReadableException e) { return ServerResponse.createByErrorCodeMessage(HttpStatus.BAD_REQUEST.value(), e.getMessage()); }
@ExceptionHandler(HttpMessageNotReadableException.class) public ResponseEntity<ErrorMessage> handleException(HttpMessageNotReadableException ex) { log.debug("Unprocessable request received: ", ex); return getErrorResponse(ex.getMessage(), HttpStatus.UNPROCESSABLE_ENTITY); }
/** * 400错误 * @param e * @return */ @ExceptionHandler(HttpMessageNotReadableException.class) public ResultMap handlerRequestNotReadable(HttpMessageNotReadableException e) { logger.error(e.getMessage(), e); return ResultMap.error(400, "http消息不可读异常"); }
@ExceptionHandler(value = HttpMessageNotReadableException.class) public ResponseEntity httpMessageException(HttpMessageNotReadableException ex, HandlerMethod handlerMethod) { log.warn("Uncatched exception of HttpMessageNotReadableException class handled in Controller: {}, message: {}", handlerMethod.getMethod().getDeclaringClass().getSimpleName(), ex.getMessage()); return new ResponseEntity<>(getTppMessages(FORMAT_ERROR), HttpStatus.BAD_REQUEST); }
@ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler({HttpMessageNotReadableException.class}) public ResponseEntity handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { LOGGER.error("参数解析失败", e); Response response = Response.failure(DefaultError.INVALID_PARAMETER); response.setExtMessage(e.getMessage()); return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); }
@ExceptionHandler(value = HttpMessageNotReadableException.class) public XPFBaseResponse exceptionHandler( HttpMessageNotReadableException ex, HttpServletResponse response){ LOG.error(ex.getMessage(),ex); return onXPFBaseException(new XPFBadRequestException("提交的内容不存在或者格式不正确"), response); }
@ExceptionHandler(value = HttpMessageNotReadableException.class) public ResponseEntity httpMessageException(HttpMessageNotReadableException ex, HandlerMethod handlerMethod) { log.warn("Uncatched exception of HttpMessageNotReadableException class handled in Controller: {}, message: {}", handlerMethod.getMethod().getDeclaringClass().getSimpleName(), ex.getMessage()); return responseErrorMapper.generateErrorResponse(createMessageError(FORMAT_ERROR)); }
@ExceptionHandler(value = HttpMessageNotReadableException.class) public ResponseEntity httpMessageException(HttpMessageNotReadableException ex, HandlerMethod handlerMethod) { log.warn("Uncatched exception of HttpMessageNotReadableException class handled in Controller: {}, message: {}", handlerMethod.getMethod().getDeclaringClass().getSimpleName(), ex.getMessage()); return responseErrorMapper.generateErrorResponse(createMessageError(FORMAT_ERROR)); }
@ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(BAD_REQUEST) public ErrorMessageResponse handleHttpMessageNotReadableException( HttpMessageNotReadableException e) { LOG.error("", e); return new ErrorMessageResponse(new ErrorMessage(e.getMessage())); }
@ExceptionHandler(HttpMessageNotReadableException.class) //@ResponseStatus(HttpStatus.BAD_REQUEST) public RestResult messageNotReadableExceptionHandler(HttpMessageNotReadableException ex) { logger.warn("---------> json convert failure, exception:{}", ex.getMessage()); return RestResultBuilder.builder().errorCode(GlobalErrorCode.BAD_REQUEST).build(); }
/** メッセージ内容の読み込み失敗例外 */ @ExceptionHandler(HttpMessageNotReadableException.class) public ResponseEntity<Map<String, String[]>> handleHttpMessageNotReadable(HttpMessageNotReadableException e) { log.warn(e.getMessage()); return new ErrorHolder(msg, locale(), "error.HttpMessageNotReadable").result(HttpStatus.BAD_REQUEST); }
/** * Exception handler converting any {@link JsonMappingException} to an <em>HTTP 400</em>. * * @param ex * @return {@link RestApiError} instance with detailed messages */ @ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) public @ResponseBody RestApiError handle(HttpMessageNotReadableException ex) { LOG.error("Exception during processing of a JSON document", ex); return RestApiError.of(ApiError.Builder.of("Invalid JSON representation").developerMessage(ex.getMessage()).build()).build(HttpStatus.BAD_REQUEST.value()); }
/** * HttpMessageNotReadableException. * http状态码为400 * * @param ex HttpMessageNotReadableException * @return ModelAndView */ @ExceptionHandler(HttpMessageNotReadableException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public ModelAndView handleHttpMessageNotReadableException(HttpMessageNotReadableException ex, HttpServletRequest request, HttpServletResponse response) { SystemException systemException = SystemException.create(DefaultErrorCode.INVALID_REQ) .set("details", ex.getMessage()); return handleSystemException(systemException, request, response); }
public ErrorBean handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { ErrorBean errorBean = new ErrorBean(); errorBean.setMessage(e.getMessage()); return errorBean;
private <T> T getOrNullAction(UriComponentsBuilder ub, Class<T> responseType) { String url = ub.toUriString(); try { ResponseEntity<T> entity = getFast(() -> { return restTemplate.getForEntity(url, responseType); }); return entity.getBody(); } catch (HttpMessageNotReadableException e) { //sometime we can receive incorrect JSON data with correct HTTP Code and content type log.error("On GET container '{}' we got error: {}", url, e.getMessage()); return null; } catch (HttpStatusCodeException e) { log.warn("Failed to execute GET on {}, due to {}", url, formatHttpException(e)); if(e.getStatusCode() == HttpStatus.NOT_FOUND) { return null; } throw e; } }
return ApiResponse.ofStatus(Status.PARAM_NOT_MATCH); } else if (e instanceof HttpMessageNotReadableException) { log.error("【全局异常拦截】HttpMessageNotReadableException: 错误信息 {}", ((HttpMessageNotReadableException) e).getMessage()); return ApiResponse.ofStatus(Status.PARAM_NOT_NULL); } else if (e instanceof BadCredentialsException) {
@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; } }