/** * Handle the case when a required parameter is missing. * <p>The default implementation sends an HTTP 400 error, and returns an empty {@code ModelAndView}. * Alternatively, a fallback view could be chosen, or the MissingServletRequestParameterException * could be rethrown as-is. * @param ex the MissingServletRequestParameterException to be handled * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage()); return new ModelAndView(); }
/** * Handle the case when a required parameter is missing. * <p>The default implementation sends an HTTP 400 error, and returns an empty {@code ModelAndView}. * Alternatively, a fallback view could be chosen, or the MissingServletRequestParameterException * could be rethrown as-is. * @param ex the MissingServletRequestParameterException to be handled * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage()); return new ModelAndView(); }
@ExceptionHandler(value = {MissingServletRequestParameterException.class}) public Result missingServletRequestParameterException(MissingServletRequestParameterException ex) { log.error("missing servlet request parameter exception:{}", ex.getMessage()); return Result.fail(ErrorType.ARGUMENT_NOT_VALID); }
/** * 错误服务请求参数异常 * @param e * @return */ @ExceptionHandler(MissingServletRequestParameterException.class) public ResultMap handlerRequestMissingServletRequest(MissingServletRequestParameterException e) { logger.error(e.getMessage(), e); return ResultMap.error(400, "错误服务请求参数异常"); }
@ExceptionHandler(value = {MissingServletRequestParameterException.class}) public Result missingServletRequestParameterException(MissingServletRequestParameterException ex) { log.error("missing servlet request parameter exception:{}", ex.getMessage()); return Result.fail(ErrorType.ARGUMENT_NOT_VALID); }
@ResponseBody @ExceptionHandler(MissingServletRequestParameterException.class) @ResponseStatus(HttpStatus.OK) public Result handleMissingServletRequestParameterException( MissingServletRequestParameterException e) { log.error(ErrorStatus.MISSING_ARGUMENT.getMessage() + ":" + e.getMessage()); return failure(ErrorStatus.MISSING_ARGUMENT,e); }
@ExceptionHandler(MissingServletRequestParameterException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public R handleError(MissingServletRequestParameterException e) { log.warn("缺少请求参数", e.getMessage()); String message = String.format("缺少必要的请求参数: %s", e.getParameterName()); return R.fail(ResultCode.PARAM_MISS, message); }
/** * Handles the case where client submitted an ill valued request (missing parameter). * * @param e exception to be handled * * @return VndErrors see {@link VndErrors} */ @ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody public VndErrors onMissingServletRequestParameterException(MissingServletRequestParameterException e) { String logref = logDebug(e); return new VndErrors(logref, e.getMessage()); }
/** * Customize the response for MissingServletRequestParameterException. * This method delegates to * {@link #handleExceptionInternal(Exception, Object, org.springframework.http.HttpHeaders, * org.springframework.http.HttpStatus, org.springframework.web.context.request.WebRequest)}. * * @param ex * the exception * @param headers * the headers to be written to the response * @param status * the selected response status * @param request * the current request * @return a {@code ResponseEntity} instance */ @Override protected ResponseEntity<Object> handleMissingServletRequestParameter( MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { final E errorResponse = createErrorResponse(status, ex.getMessage()); logException(ex, errorResponse, request); return new ResponseEntity<>(errorResponse, status); }
builder.append(ex.getParameterName()); builder.append("校验不通过"); failedResponseBuilder.exception(builder.toString()).msg(ex.getMessage()); return failedResponseBuilder; } else if (exception instanceof MissingPathVariableException) {