@Override public void run() { Response response; // Retry until the retry limit has been reached. for (int i = 0; i < rateLimitRetry; ++i) { try { response = api(request); } catch (IOException ex) { // Stop retrying if there is a network error. callback.error(ex); return; } // We have been rate limited. if (response.getStatusCode() == RATE_LIMIT_RESPONSE_CODE) { try { Thread.sleep(rateLimitSleep); } catch (InterruptedException ex) { // Can safely ignore this exception and retry. } } else { callback.response(response); return; } } // Retries exhausted. Return error. callback.error(new RateLimitException(request, rateLimitRetry)); } });
@Override public void run() { Response response; // Retry until the retry limit has been reached. for (int i = 0; i < rateLimitRetry; ++i) { try { response = api(request); } catch (IOException ex) { // Stop retrying if there is a network error. callback.error(ex); return; } // We have been rate limited. if (response.getStatusCode() == RATE_LIMIT_RESPONSE_CODE) { try { Thread.sleep(rateLimitSleep); } catch (InterruptedException ex) { // Can safely ignore this exception and retry. } } else { callback.response(response); return; } } // Retries exhausted. Return error. callback.error(new RateLimitException(request, rateLimitRetry)); } });