Search in sources :

Example 1 with ValidationException

use of com.tyndalehouse.step.core.exceptions.ValidationException in project step by STEPBible.

the class AbstractAjaxController method getExceptionMessageAndLog.

/**
 * Gets the exception message.
 *
 * @param e the e
 * @return the exception message
 */
private String getExceptionMessageAndLog(final Throwable e) {
    LOGGER.trace("Tracing exception: ", e);
    final Locale locale = this.clientSessionProvider.get().getLocale();
    final ResourceBundle bundle = ResourceBundle.getBundle("ErrorBundle", locale);
    if (!(e instanceof StepInternalException)) {
        return returnInternalError(e, bundle);
    }
    // else we're looking at a STEP caught exception
    if (e instanceof LocalisedException) {
        return e.getMessage();
    }
    if (e instanceof TranslatedException) {
        final TranslatedException translatedException = (TranslatedException) e;
        LOGGER.warn(e.getMessage());
        LOGGER.debug(e.getMessage(), e);
        return format(bundle.getString(translatedException.getMessage()), translatedException.getArgs());
    }
    if (e instanceof ValidationException) {
        final ValidationException validationException = (ValidationException) e;
        switch(validationException.getExceptionType()) {
            case LOGIN_REQUIRED:
                return bundle.getString("error_login");
            case USER_MISSING_FIELD:
                return bundle.getString("error_missing_field");
            case USER_VALIDATION_ERROR:
                return bundle.getString("error_validation");
            case APP_MISSING_FIELD:
            case CONTROLLER_INITIALISATION_ERROR:
            case SERVICE_VALIDATION_ERROR:
            default:
                return returnInternalError(e, bundle);
        }
    }
    return returnInternalError(e, bundle);
}
Also used : Locale(java.util.Locale) LocalisedException(com.tyndalehouse.step.core.exceptions.LocalisedException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) ValidationException(com.tyndalehouse.step.core.exceptions.ValidationException) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) ResourceBundle(java.util.ResourceBundle)

Aggregations

LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)1 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)1 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)1 ValidationException (com.tyndalehouse.step.core.exceptions.ValidationException)1 Locale (java.util.Locale)1 ResourceBundle (java.util.ResourceBundle)1