Skip to content

Instantly share code, notes, and snippets.

@KiryhaPikoff
Created July 18, 2019 19:21
Show Gist options
  • Select an option

  • Save KiryhaPikoff/6e24fa270d86c04cfcf49e4b2fef4377 to your computer and use it in GitHub Desktop.

Select an option

Save KiryhaPikoff/6e24fa270d86c04cfcf49e4b2fef4377 to your computer and use it in GitHub Desktop.
@ResponseBody
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<StringBuilder> processValidationError(HttpServletRequest httpServletRequest, MethodArgumentNotValidException manve) throws MethodArgumentNotValidException {
StringBuilder response = new StringBuilder();
for (ObjectError oe : manve.getBindingResult().getAllErrors() ) {
response.append(oe.getDefaultMessage() + "\n");
}
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment