Implemented a strategy pattern to let the client determine API rate limit behavior.

The default is set to the backward compatible behaviour.
This commit is contained in:
Kohsuke Kawaguchi
2015-03-17 07:43:51 -07:00
parent a4c1c8de24
commit 4093e53b5b
4 changed files with 74 additions and 11 deletions

View File

@@ -417,18 +417,11 @@ class Requester {
}
/**
* If the error is because of the API limit, wait 10 sec and return normally.
* Otherwise throw an exception reporting an error.
* Handle API error by either throwing it or by returning normally to retry.
*/
/*package*/ void handleApiError(IOException e, HttpURLConnection uc) throws IOException {
if ("0".equals(uc.getHeaderField("X-RateLimit-Remaining"))) {
// API limit reached. wait 10 secs and return normally
try {
Thread.sleep(10000);
return;
} catch (InterruptedException _) {
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
}
root.rateLimitHandler.onError(e,uc);
}
if (e instanceof FileNotFoundException)