diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/Helper.java b/Kitodo/src/main/java/org/kitodo/production/helper/Helper.java index 1c99409da75..47a57b8797b 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/Helper.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/Helper.java @@ -162,12 +162,23 @@ public static void setErrorMessage(String title, final Object[] parameters) { public static void setErrorMessage(String title, Logger logger, Exception exception) { logger.error(title, exception); if (Objects.isNull(exception.getMessage()) || exception.getMessage().equals(title)) { - setErrorMessage(title); + setErrorMessage(getRootCause(exception)); } else { setErrorMessage(title, exception.getMessage()); } } + private static String getRootCause(Throwable problem) { + Throwable cause = problem.getCause(); + String className = problem.getClass().getSimpleName(); + if (Objects.nonNull(cause)) { + return className + " / " + getRootCause(cause); + } else { + String message = problem.getLocalizedMessage(); + return StringUtils.isEmpty(message) ? className : className + ": " + message; + } + } + /** * Set error message to message tag with given name 'title'. Substitute all * placeholders in message tag with elements of given array 'parameters'. @@ -269,18 +280,11 @@ public static void setMessage(String control, String message, String description } /** - * Dem aktuellen Formular eine Fehlermeldung für ein bestimmtes Control - * übergeben. + * Transfer an error message for a specific control to the current form. */ private static void setMessage(String control, String message, String description, MessageLevel level) { - // Never forget: Strings are immutable - message = Objects.toString(message).replaceAll("<", "<"); - message = message.replaceAll(">", ">"); - description = Objects.toString(description).replaceAll("<", "<"); - description = description.replaceAll(">", ">"); - - String msg = getTranslation(message); - String descript = getTranslation(description); + String msg = getTranslation(Objects.toString(message)); + String descript = getTranslation(Objects.toString(description)); String compoundMessage = msg.replaceFirst(":\\s*$", ""); if (StringUtils.isNotEmpty(descript)) {