Search in sources :

Example 1 with ValidationErrors

use of org.summerb.approaches.validation.ValidationErrors in project summerb by skarpushin.

the class RestAuthenticationFailureHandler method onAuthenticationFailure.

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
    FieldValidationException fve = ExceptionUtils.findExceptionOfType(exception, FieldValidationException.class);
    if (fve != null) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        jsonResponseHelper.writeResponseBody(new ValidationErrors(fve.getErrors()), response);
        return;
    }
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    GenericServerErrorResult responseBody = new GenericServerErrorResult(exceptionTranslator.buildUserMessage(exception, LocaleContextHolder.getLocale()), new ExceptionInfo(exception));
    jsonResponseHelper.writeResponseBody(responseBody, response);
}
Also used : FieldValidationException(org.summerb.approaches.validation.FieldValidationException) ValidationErrors(org.summerb.approaches.validation.ValidationErrors) GenericServerErrorResult(org.summerb.utils.exceptions.dto.GenericServerErrorResult) ExceptionInfo(org.summerb.utils.exceptions.dto.ExceptionInfo)

Aggregations

FieldValidationException (org.summerb.approaches.validation.FieldValidationException)1 ValidationErrors (org.summerb.approaches.validation.ValidationErrors)1 ExceptionInfo (org.summerb.utils.exceptions.dto.ExceptionInfo)1 GenericServerErrorResult (org.summerb.utils.exceptions.dto.GenericServerErrorResult)1