default Optional<Integer> status( // final RequestAttributes requestAttributes, // final Location location, // final T throwable // ) { final ExceptionTranslator exceptionTranslator = this.getExceptionTranslator(); final Optional<Integer> translated = exceptionTranslator != null ? // exceptionTranslator.status(location) : // Optional.empty(); final Integer fromAttribute = this.getAttribute(requestAttributes, "javax.servlet.error.status_code"); return translated.isPresent() ? translated : Optional.ofNullable(fromAttribute); }
exceptionResolver.setConversionService(conversionService); exceptionResolver.setExceptionTranslator(exceptionTranslator); exceptionResolver.setStackTraceIndicator(stackTraceIndicator); });
default Optional<Location> find(final T throwable) { final ExceptionTranslator exceptionTranslator = this.getExceptionTranslator(); return exceptionTranslator != null ? exceptionTranslator.find(throwable) : Optional.empty(); }
default <E extends Throwable> String message( // final RequestAttributes requestAttributes, // final E throwable, // final Optional<List<ValidationError>> errorsOptional // ) { final Object fromAttribute = getAttribute(requestAttributes, "javax.servlet.error.message"); final String fromError; if (throwable != null) { if (!errorsOptional.isPresent()) { fromError = throwable.getMessage(); } else { final int errorCount = errorsOptional.get().size(); fromError = errorCount > 0 ? "Validation failed. Error count: " + errorCount : "No errors"; } } else { fromError = null; } final String result; if ((!isEmpty(fromAttribute) || fromError == null) && !(throwable instanceof BindingResult)) { result = isEmpty(fromAttribute) ? "No message available" : fromAttribute.toString(); } else { result = fromError; } return result; }
exceptionResolver.setConversionService(conversionService); exceptionResolver.setExceptionTranslator(exceptionTranslator); exceptionResolver.setStackTraceIndicator(stackTraceIndicator); });
default Optional<Location> find(final T throwable) { final ExceptionTranslator exceptionTranslator = this.getExceptionTranslator(); return exceptionTranslator != null ? exceptionTranslator.find(throwable) : Optional.empty(); }
default <E extends Throwable> String message( // final RequestAttributes requestAttributes, // final E throwable, // final Optional<List<ValidationError>> errorsOptional // ) { final Object fromAttribute = getAttribute(requestAttributes, "javax.servlet.error.message"); final String fromError; if (throwable != null) { if (!errorsOptional.isPresent()) { fromError = throwable.getMessage(); } else { final int errorCount = errorsOptional.get().size(); fromError = errorCount > 0 ? "Validation failed. Error count: " + errorCount : "No errors"; } } else { fromError = null; } final String result; if ((!isEmpty(fromAttribute) || fromError == null) && !(throwable instanceof BindingResult)) { result = isEmpty(fromAttribute) ? "No message available" : fromAttribute.toString(); } else { result = fromError; } return result; }
default Optional<Integer> status( // final RequestAttributes requestAttributes, // final Location location, // final T throwable // ) { final ExceptionTranslator exceptionTranslator = this.getExceptionTranslator(); final Optional<Integer> translated = exceptionTranslator != null ? // exceptionTranslator.status(location) : // Optional.empty(); final Integer fromAttribute = this.getAttribute(requestAttributes, "javax.servlet.error.status_code"); return translated.isPresent() ? translated : Optional.ofNullable(fromAttribute); }
/** * Translate exception and generates localizedMessage. * * @param request The current request. * @param location The location get data from. * @param throwable throwable * @return A TranslateResult. */ default Optional<String> localizedMessage( // final RequestAttributes request, // final Location location, // final T throwable // ) { final ExceptionTranslator exceptionTranslator = this.getExceptionTranslator(); final Optional<String> result; if (exceptionTranslator != null) { final Map<String, Serializable> contextVariables = ImmutableMap.of(); final String template = exceptionTranslator.template(location).orElse(null); result = exceptionTranslator.localizedMessage(template, request, throwable, contextVariables); } else { result = Optional.empty(); } return result; }
/** * Translate exception and generates localizedMessage. * * @param request The current request. * @param location The location get data from. * @param throwable throwable * @return A TranslateResult. */ default Optional<String> localizedMessage( // final RequestAttributes request, // final Location location, // final T throwable // ) { final ExceptionTranslator exceptionTranslator = this.getExceptionTranslator(); final Optional<String> result; if (exceptionTranslator != null) { final Map<String, Serializable> contextVariables = ImmutableMap.of(); final String template = exceptionTranslator.template(location).orElse(null); result = exceptionTranslator.localizedMessage(template, request, throwable, contextVariables); } else { result = Optional.empty(); } return result; }