use of com.breuninger.arch.playground.common.domain.ValidationError in project arch-playground by BeneStem.
the class ExceptionHandlerHtmlControllerAdvice method handleConstraintViolation.
@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ModelAndView handleConstraintViolation(final ConstraintViolationException exception) {
final MappingJackson2JsonView view = new CustomMappingJackson2JsonView();
final var modelAndView = new ModelAndView(view);
modelAndView.addObject(exception.getConstraintViolations().stream().map(constraintViolation -> new ValidationError(((PathImpl) constraintViolation.getPropertyPath()).getLeafNode().getName(), constraintViolation.getMessage())).collect(toList()));
return modelAndView;
}
use of com.breuninger.arch.playground.common.domain.ValidationError in project arch-playground by BeneStem.
the class ExceptionHandlerHtmlControllerAdvice method handleBadRequest.
// @ExceptionHandler(RedirectionException.class)
// public RedirectView redirection(final RedirectionException exception) {
// final RedirectView loginRedirectView = new RedirectView(exception.getLocation().toString());
// loginRedirectView.setStatusCode(HttpStatus.valueOf(exception.getResponse().getStatus()));
// loginRedirectView.setExposeModelAttributes(false);
// return loginRedirectView;
// }
@ExceptionHandler(BadRequestException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ModelAndView handleBadRequest(final BadRequestException exception) {
final MappingJackson2JsonView view = new CustomMappingJackson2JsonView();
final var modelAndView = new ModelAndView(view);
modelAndView.addObject(exception.getErrors().getFieldErrors().stream().map(fieldError -> new ValidationError(fieldError.getField(), fieldError.getDefaultMessage())).collect(toList()));
return modelAndView;
}
use of com.breuninger.arch.playground.common.domain.ValidationError in project arch-playground by BeneStem.
the class ExceptionHandlerHtmlControllerAdvice method handleMethodArgumentNotValid.
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
protected ModelAndView handleMethodArgumentNotValid(final MethodArgumentNotValidException exception) {
final MappingJackson2JsonView view = new CustomMappingJackson2JsonView();
final var modelAndView = new ModelAndView(view);
modelAndView.addObject(exception.getBindingResult().getFieldErrors().stream().map(fieldError -> new ValidationError(fieldError.getField(), fieldError.getDefaultMessage())).collect(toList()));
return modelAndView;
}
Aggregations