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); }
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); }
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; }