@VisibleForTesting static <T> T executeWithRetries( AbstractGoogleClientRequest<T> request, String errorMessage, Sleeper sleeper, BackOff backoff, SerializableFunction<IOException, Boolean> shouldRetry) throws IOException, InterruptedException { Exception lastException = null; do { try { return request.execute(); } catch (IOException e) { lastException = e; if (!shouldRetry.apply(e)) { break; } LOG.info("Ignore the error and retry the request.", e); } } while (nextBackOff(sleeper, backoff)); throw new IOException(errorMessage, lastException); }