Skip to content

Commit

Permalink
Display root cause of error with its message
Browse files Browse the repository at this point in the history
Fixes  #4073
  • Loading branch information
Matthias Ronge authored Oct 28, 2020
1 parent faeecab commit c76696c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Kitodo/src/main/java/org/kitodo/production/helper/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -161,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 @@ -272,12 +284,6 @@ public static void setMessage(String control, String message, String description
* übergeben.
*/
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);

Expand Down

0 comments on commit c76696c

Please sign in to comment.