Better handling of IOException in CF connection errors

This commit is contained in:
nsingh
2017-01-17 11:05:14 -08:00
parent f25d2c9c94
commit 5d00f4447e
2 changed files with 25 additions and 2 deletions

View File

@@ -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

View File

@@ -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()));