use of pl.pollub.cs.pentagoncafe.flare.exception.handler.error.ApiFieldError in project Flare-event-calendar by PollubCafe.
the class GlobalExceptionHandler method handleMethodArgumentNotValid.
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
BindingResult bindingResult = ex.getBindingResult();
List<ApiFieldError> apiFieldErrors = bindingResult.getFieldErrors().stream().map(fieldError -> new ApiFieldError(fieldError.getField(), fieldError.getDefaultMessage())).collect(toList());
ApiErrorsView apiErrorsView = new ApiErrorsView(apiFieldErrors);
return new ResponseEntity<>(apiErrorsView, HttpStatus.UNPROCESSABLE_ENTITY);
}
Aggregations