Search in sources :

Example 1 with ApiFieldError

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);
}
Also used : RegistrationException(pl.pollub.cs.pentagoncafe.flare.exception.registration.RegistrationException) SendingEmailException(pl.pollub.cs.pentagoncafe.flare.exception.sendingEmail.SendingEmailException) ObjectNotFoundException(pl.pollub.cs.pentagoncafe.flare.exception.ObjectNotFoundException) WebRequest(org.springframework.web.context.request.WebRequest) Autowired(org.springframework.beans.factory.annotation.Autowired) BindingResult(org.springframework.validation.BindingResult) ApiErrorsView(pl.pollub.cs.pentagoncafe.flare.exception.handler.error.ApiErrorsView) TooManyLoginAttempts(pl.pollub.cs.pentagoncafe.flare.exception.auth.TooManyLoginAttempts) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) EventCalendarApplication(pl.pollub.cs.pentagoncafe.flare.EventCalendarApplication) ControllerAdvice(org.springframework.web.bind.annotation.ControllerAdvice) Messages(pl.pollub.cs.pentagoncafe.flare.component.message.Messages) HttpHeaders(org.springframework.http.HttpHeaders) ResetPasswordException(pl.pollub.cs.pentagoncafe.flare.exception.ResetPasswordException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) ApiFieldError(pl.pollub.cs.pentagoncafe.flare.exception.handler.error.ApiFieldError) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Logger(org.apache.logging.log4j.Logger) ResponseEntityExceptionHandler(org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler) ResponseEntity(org.springframework.http.ResponseEntity) LogManager(org.apache.logging.log4j.LogManager) BindingResult(org.springframework.validation.BindingResult) ResponseEntity(org.springframework.http.ResponseEntity) ApiErrorsView(pl.pollub.cs.pentagoncafe.flare.exception.handler.error.ApiErrorsView) ApiFieldError(pl.pollub.cs.pentagoncafe.flare.exception.handler.error.ApiFieldError)

Aggregations

List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpStatus (org.springframework.http.HttpStatus)1 ResponseEntity (org.springframework.http.ResponseEntity)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 BindingResult (org.springframework.validation.BindingResult)1 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)1 ControllerAdvice (org.springframework.web.bind.annotation.ControllerAdvice)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 WebRequest (org.springframework.web.context.request.WebRequest)1 ResponseEntityExceptionHandler (org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)1 EventCalendarApplication (pl.pollub.cs.pentagoncafe.flare.EventCalendarApplication)1 Messages (pl.pollub.cs.pentagoncafe.flare.component.message.Messages)1 ObjectNotFoundException (pl.pollub.cs.pentagoncafe.flare.exception.ObjectNotFoundException)1 ResetPasswordException (pl.pollub.cs.pentagoncafe.flare.exception.ResetPasswordException)1