io.bdeploy.common.util.ExceptionHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api Show documentation
Show all versions of api Show documentation
Public API including dependencies, ready to be used for integrations and plugins.
package io.bdeploy.common.util;
import java.lang.reflect.InvocationTargetException;
import jakarta.ws.rs.ProcessingException;
public class ExceptionHelper {
private ExceptionHelper() {
}
public static String mapExceptionCausesToReason(Throwable exception) {
if (exception == null) {
return "";
}
StringBuilder reason = new StringBuilder();
Throwable current = exception;
String last = null;
do {
String message = current.getMessage();
boolean ignore = isIgnorableExceptionType(current) || message == null || message.equals(last);
if (!ignore) {
reason.append(message);
}
last = message;
if (current instanceof InvocationTargetException) {
current = ((InvocationTargetException) current).getTargetException();
} else {
if (current == current.getCause()) {
break;
}
current = current.getCause();
}
if (current != null && !ignore) {
reason.append("; ");
}
} while (current != null);
return reason.toString();
}
private static boolean isIgnorableExceptionType(Throwable current) {
// add more if required.
return current instanceof ProcessingException;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy