class DefaultFailureDiagnostics implements FailureDiagnostics<BackgroundException> {

    @Override
    public Type determine(final BackgroundException failure) {
        if(log.isDebugEnabled()) {
            log.debug(String.format("Determine cause for failure %s", failure));
        }
        for(Throwable cause : ExceptionUtils.getThrowableList(failure)) {
            if(failure instanceof UnsupportedException) {
                return Type.unsupported;
            }
            if(failure instanceof LoginFailureException) {
                return Type.login;
            }
            if(cause instanceof ResolveFailedException) {
                return Type.network;
            }
            if(failure instanceof ConnectionCanceledException) {
                return Type.cancel;
            }
            if(cause instanceof ConnectionTimeoutException) {
                return Type.network;
            }
            if(cause instanceof ConnectionRefusedException) {
                return Type.network;
            }
            if(cause instanceof SSLNegotiateException) {
                return Type.application;
            }
            if(cause instanceof SSLHandshakeException) {
                return Type.application;
            }
            if(cause instanceof SSLException) {
                return Type.network;
            }
            if(cause instanceof NoHttpResponseException) {
                return Type.network;
            }
            if(cause instanceof ConnectTimeoutException) {
                return Type.network;
            }
            if(cause instanceof SocketException
                || cause instanceof IOResumeException
                || cause instanceof TimeoutException // Used in Promise#retrieve
                || cause instanceof SocketTimeoutException
                || cause instanceof UnknownHostException) {
                return Type.network;
            }
        }
        return Type.application;
    }

}