Better handling of IOException in CF connection errors
This commit is contained in:
@@ -33,6 +33,29 @@ public class ExceptionUtil {
|
||||
}
|
||||
return cause;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param e
|
||||
* @param toLookFor type of throwable to look for in the given throwable.
|
||||
* @return the throwable instance of the given type, or null if nothing found.
|
||||
*/
|
||||
public static Throwable getThrowable(Throwable e, Class<? extends Throwable> toLookFor) {
|
||||
if (e.getClass().equals(toLookFor)) {
|
||||
return e;
|
||||
}
|
||||
|
||||
Throwable cause = e;
|
||||
Throwable parent = e.getCause();
|
||||
while (parent != null && parent != e) {
|
||||
cause = parent;
|
||||
parent = cause.getCause();
|
||||
if (cause.getClass().equals(toLookFor)) {
|
||||
return cause;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getMessage(Throwable e) {
|
||||
// The message of nested exception is usually more interesting than the
|
||||
|
||||
@@ -50,9 +50,9 @@ public abstract class AbstractCFHintsProvider implements Provider<Collection<YVa
|
||||
hints.addAll(resolvedHints);
|
||||
} catch (Throwable e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
// Don't throw exception as to allow the CA to be displayed to the
|
||||
// Don't propagate exception as to allow the CA to be displayed to the
|
||||
// user.
|
||||
if (e instanceof IOException || ExceptionUtil.getDeepestCause(e) instanceof IOException) {
|
||||
if (ExceptionUtil.getThrowable(e, IOException.class) != null) {
|
||||
hints.add(new BasicYValueHint(EMPTY_VALUE, "Connection failure. " + e.getMessage()));
|
||||
} else {
|
||||
hints.add(new BasicYValueHint(EMPTY_VALUE, e.getMessage()));
|
||||
|
||||
Reference in New Issue
Block a user