Java Code Examples for org.springframework.web.bind.MissingServletRequestParameterException#getMessage()

The following examples show how to use org.springframework.web.bind.MissingServletRequestParameterException#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: GlobalExceptionHandler.java    From Spring-Boot-Book with Apache License 2.0 5 votes vote down vote up
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public String handleMissingServletRequestParameterException(MissingServletRequestParameterException e, Model model) {
    logger.error("缺少请求参数", e);
    String message = "【缺少请求参数】" + e.getMessage();
    model.addAttribute("message", message);
    model.addAttribute("code", 400);
    return viewName;
}
 
Example 2
Source File: GlobalExceptionHandler.java    From Spring-Boot-Book with Apache License 2.0 5 votes vote down vote up
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public String handleMissingServletRequestParameterException(MissingServletRequestParameterException e, Model model) {
    logger.error("缺少请求参数", e);
    String message = "【缺少请求参数】" + e.getMessage();
    model.addAttribute("message", message);
    model.addAttribute("code", 400);
    return viewName;
}
 
Example 3
Source File: GlobalExceptionHandler.java    From SENS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public String handleMissingServletRequestParameterException(MissingServletRequestParameterException e, Model model) {
    log.error("缺少请求参数", e);
    String message = "【缺少请求参数】" + e.getMessage();
    model.addAttribute("message", message);
    model.addAttribute("code", 400);
    return viewName;
}
 
Example 4
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public ResponseEntity<ErrorMessage> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex
) {

	List<String> errors = new ArrayList<>();
	String error = ex.getParameterName() + ", " + ex.getMessage();
	errors.add(error);
	ErrorMessage errorMessage = new ErrorMessage(errors);
	return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST);
}
 
Example 5
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public ResponseEntity<ErrorMessage> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex
) {

	List<String> errors = new ArrayList<>();
	String error = ex.getParameterName() + ", " + ex.getMessage();
	errors.add(error);
	ErrorMessage errorMessage = new ErrorMessage(errors);
	return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST);
}
 
Example 6
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public ResponseEntity<ErrorMessage> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex
) {

	List<String> errors = new ArrayList<>();
	String error = ex.getParameterName() + ", " + ex.getMessage();
	errors.add(error);
	ErrorMessage errorMessage = new ErrorMessage(errors);
	return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST);
}
 
Example 7
Source File: OAuthErrorResponse.java    From authmore-framework with Apache License 2.0 4 votes vote down vote up
public OAuthErrorResponse(MissingServletRequestParameterException e) {
    this("invalid request parameters", e.getMessage());
}
 
Example 8
Source File: GlobalExceptionHandler.java    From java-pay with Apache License 2.0 4 votes vote down vote up
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public ExceptionResult handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
    logger.error("{}", e.getMessage());
    return new ExceptionResult(40005, e.getMessage());
}
 
Example 9
Source File: ExceptionProcessor.java    From personal_book_library_web_project with MIT License 4 votes vote down vote up
@ExceptionHandler(MissingServletRequestParameterException.class)
  @ResponseStatus(value = HttpStatus.NOT_FOUND)
  @ResponseBody
  public ServiceExceptionDetails processMissingServletRequestParameterException(HttpServletRequest httpServletRequest, MissingServletRequestParameterException exception) {

String missingParameterName = exception.getParameterName();
String missingParameterType = exception.getParameterType();

String errorMessage = "Missing parameter: [name: " + missingParameterName + ", type: " + missingParameterType + "]";

String detailedErrorMessage = exception.getMessage();
       
      String errorURL = httpServletRequest.getRequestURL().toString();
       
      return new ServiceExceptionDetails(errorMessage, detailedErrorMessage, errorURL);
  }