Skip to content

Commit

Permalink
Display root cause of error with its message
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Ronge committed Nov 4, 2020
1 parent 0c34a2e commit c770184
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions Kitodo/src/main/java/org/kitodo/production/helper/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down Expand Up @@ -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("<", "&lt;");
message = message.replaceAll(">", "&gt;");
description = Objects.toString(description).replaceAll("<", "&lt;");
description = description.replaceAll(">", "&gt;");

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)) {
Expand Down

0 comments on commit c770184

Please sign in to comment.