ApiErrorExtractor { public boolean socketError(Throwable throwable) { if (throwable instanceof SocketException || throwable instanceof SocketTimeoutException) { return true; } Throwable cause = throwable.getCause(); if (throwable instanceof SSLException && cause != null && ioError(cause)) { return true; } return cause != null && socketError(cause); }  boolean requestFailure(IOException e); boolean accessDenied(IOException e); boolean badRequest(IOException e); boolean unauthorized(IOException e); boolean accessDeniedNonRecoverable(IOException e); boolean clientError(IOException e); boolean internalServerError(IOException e); boolean itemAlreadyExists(IOException e); boolean itemNotFound(IOException e); boolean fieldSizeTooLarge(IOException e); boolean resourceNotReady(IOException e); boolean preconditionNotMet(IOException e); boolean rangeNotSatisfiable(IOException e); boolean rateLimited(IOException e); boolean quotaExceeded(IOException e); boolean userProjectMissing(IOException e); boolean ioError(Throwable throwable); boolean socketError(Throwable throwable); boolean readTimedOut(IOException e); String getErrorMessage(IOException e); IOException toUserPresentableException(IOException e, String action); String toUserPresentableMessage(IOException e, @Nullable String action); String toUserPresentableMessage(IOException e); @Nullable String getDebugInfo(IOException e); @Nullable static GoogleJsonResponseException getJsonResponseException(Throwable throwable); static final ApiErrorExtractor INSTANCE; static final int STATUS_CODE_RANGE_NOT_SATISFIABLE; static final String GLOBAL_DOMAIN; static final String USAGE_LIMITS_DOMAIN; static final String RATE_LIMITED_REASON; static final String USER_RATE_LIMITED_REASON; static final String QUOTA_EXCEEDED_REASON; static final String ACCOUNT_DISABLED_REASON; static final String ACCESS_NOT_CONFIGURED_REASON; static final String RESOURCE_NOT_READY_REASON; static final String FIELD_SIZE_TOO_LARGE_REASON; static final String USER_PROJECT_MISSING_MESSAGE; }
@Test public void testSocketError() { Throwable socketError1 = new SocketTimeoutException("socket error 1"); assertThat(errorExtractor.socketError(socketError1)).isTrue(); assertThat(errorExtractor.socketError(new Exception(socketError1))).isTrue(); assertThat(errorExtractor.socketError(new IOException(new IOException(socketError1)))).isTrue(); Throwable socketError2 = new SocketException("socket error 2"); assertThat(errorExtractor.socketError(socketError2)).isTrue(); assertThat(errorExtractor.socketError(new Exception(socketError2))).isTrue(); assertThat(errorExtractor.socketError(new IOException(new IOException(socketError2)))).isTrue(); Throwable socketError3 = new SSLException("ssl exception", new EOFException("eof")); assertThat(errorExtractor.socketError(socketError3)).isTrue(); assertThat(errorExtractor.socketError(new Exception(socketError3))).isTrue(); assertThat(errorExtractor.socketError(new IOException(new IOException(socketError3)))).isTrue(); Throwable notSocketError = new Exception("not socket error"); Throwable notIOError = new Exception("not io error"); assertThat(errorExtractor.socketError(notSocketError)).isFalse(); assertThat(errorExtractor.socketError(new IOException(notSocketError))).isFalse(); assertThat(errorExtractor.socketError(new SSLException("handshake failed", notIOError))) .isFalse(); }