Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display root cause of error with its message #4074

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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