Search in sources :

Example 1 with ValidationErrors

use of org.summerb.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.validation.FieldValidationException) ValidationErrors(org.summerb.validation.ValidationErrors) GenericServerErrorResult(org.summerb.utils.exceptions.dto.GenericServerErrorResult) ExceptionInfo(org.summerb.utils.exceptions.dto.ExceptionInfo)

Aggregations

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