forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate limit handlers using HttpURLConnection
- Loading branch information
1 parent
1535817
commit 4846442
Showing
16 changed files
with
361 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/kohsuke/github/GitHubAbuseLimitHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.kohsuke.github; | ||
|
||
import org.kohsuke.github.connector.GitHubConnectorResponse; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Pluggable strategy to determine what to do when the API rate limit is reached. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
* @see GitHubBuilder#withAbuseLimitHandler(AbuseLimitHandler) GitHubBuilder#withRateLimitHandler(AbuseLimitHandler) | ||
* @see GitHubRateLimitHandler | ||
*/ | ||
public abstract class GitHubAbuseLimitHandler extends GitHubConnectorResponseErrorHandler { | ||
|
||
@Override | ||
boolean isError(@Nonnull GitHubConnectorResponse connectorResponse) throws IOException { | ||
return connectorResponse.statusCode() == HttpURLConnection.HTTP_FORBIDDEN | ||
&& connectorResponse.header("Retry-After") != null; | ||
} | ||
|
||
/** | ||
* Called when the library encounters HTTP error indicating that the API abuse limit is reached. | ||
* | ||
* <p> | ||
* Any exception thrown from this method will cause the request to fail, and the caller of github-api will receive | ||
* an exception. If this method returns normally, another request will be attempted. For that to make sense, the | ||
* implementation needs to wait for some time. | ||
* | ||
* @param connectorResponse | ||
* Response information for this request. | ||
* @throws IOException | ||
* on failure | ||
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">API documentation from GitHub</a> | ||
* @see <a href= | ||
* "https://developer.github.com/v3/guides/best-practices-for-integrators/#dealing-with-abuse-rate-limits">Dealing | ||
* with abuse rate limits</a> | ||
* | ||
*/ | ||
public abstract void onError(@Nonnull GitHubConnectorResponse connectorResponse) throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.