diff --git a/src/main/java/org/kohsuke/github/GitHubAbuseLimitHandler.java b/src/main/java/org/kohsuke/github/GitHubAbuseLimitHandler.java index 2c05dd1455..5dda9c42d0 100644 --- a/src/main/java/org/kohsuke/github/GitHubAbuseLimitHandler.java +++ b/src/main/java/org/kohsuke/github/GitHubAbuseLimitHandler.java @@ -97,6 +97,21 @@ static long parseWaitTime(GitHubConnectorResponse connectorResponse) { public GitHubAbuseLimitHandler() { } + /** + * Checks if is error. + * + * @param connectorResponse + * the connector response + * @return true, if is error + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Override + public boolean isError(@Nonnull GitHubConnectorResponse connectorResponse) throws IOException { + return isTooManyRequests(connectorResponse) + || (isForbidden(connectorResponse) && hasRetryOrLimitHeader(connectorResponse)); + } + /** * Called when the library encounters HTTP error indicating that the API abuse limit is reached. * @@ -168,19 +183,4 @@ private boolean isTooManyRequests(GitHubConnectorResponse connectorResponse) { return connectorResponse.statusCode() == TOO_MANY_REQUESTS; } - /** - * Checks if is error. - * - * @param connectorResponse - * the connector response - * @return true, if is error - * @throws IOException - * Signals that an I/O exception has occurred. - */ - @Override - boolean isError(@Nonnull GitHubConnectorResponse connectorResponse) { - return isTooManyRequests(connectorResponse) - || (isForbidden(connectorResponse) && hasRetryOrLimitHeader(connectorResponse)); - } - } diff --git a/src/main/java/org/kohsuke/github/GitHubConnectorResponseErrorHandler.java b/src/main/java/org/kohsuke/github/GitHubConnectorResponseErrorHandler.java index cb729e321c..5a50b10c4f 100644 --- a/src/main/java/org/kohsuke/github/GitHubConnectorResponseErrorHandler.java +++ b/src/main/java/org/kohsuke/github/GitHubConnectorResponseErrorHandler.java @@ -84,6 +84,17 @@ private boolean isServiceDown(GitHubConnectorResponse connectorResponse) throws } }; + /** + * Called to detect an error handled by this handler. + * + * @param connectorResponse + * the connector response + * @return {@code true} if there is an error and {@link #onError(GitHubConnectorResponse)} should be called + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public abstract boolean isError(@Nonnull GitHubConnectorResponse connectorResponse) throws IOException; + /** * Called when the library encounters HTTP error matching {@link #isError(GitHubConnectorResponse)} * @@ -100,15 +111,4 @@ private boolean isServiceDown(GitHubConnectorResponse connectorResponse) throws * @see API documentation from GitHub */ public abstract void onError(@Nonnull GitHubConnectorResponse connectorResponse) throws IOException; - - /** - * Called to detect an error handled by this handler. - * - * @param connectorResponse - * the connector response - * @return {@code true} if there is an error and {@link #onError(GitHubConnectorResponse)} should be called - * @throws IOException - * Signals that an I/O exception has occurred. - */ - abstract boolean isError(@Nonnull GitHubConnectorResponse connectorResponse) throws IOException; } diff --git a/src/main/java/org/kohsuke/github/GitHubRateLimitHandler.java b/src/main/java/org/kohsuke/github/GitHubRateLimitHandler.java index dd6149b1bd..fae55619c0 100644 --- a/src/main/java/org/kohsuke/github/GitHubRateLimitHandler.java +++ b/src/main/java/org/kohsuke/github/GitHubRateLimitHandler.java @@ -64,6 +64,21 @@ public void onError(GitHubConnectorResponse connectorResponse) throws IOExceptio public GitHubRateLimitHandler() { } + /** + * Checks if is error. + * + * @param connectorResponse + * the connector response + * @return true, if is error + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Override + public boolean isError(@NotNull GitHubConnectorResponse connectorResponse) throws IOException { + return connectorResponse.statusCode() == HTTP_FORBIDDEN + && "0".equals(connectorResponse.header("X-RateLimit-Remaining")); + } + /** * Called when the library encounters HTTP error indicating that the API rate limit has been exceeded. * @@ -81,21 +96,6 @@ public GitHubRateLimitHandler() { */ public abstract void onError(@Nonnull GitHubConnectorResponse connectorResponse) throws IOException; - /** - * Checks if is error. - * - * @param connectorResponse - * the connector response - * @return true, if is error - * @throws IOException - * Signals that an I/O exception has occurred. - */ - @Override - boolean isError(@NotNull GitHubConnectorResponse connectorResponse) throws IOException { - return connectorResponse.statusCode() == HTTP_FORBIDDEN - && "0".equals(connectorResponse.header("X-RateLimit-Remaining")); - } - /* * Exposed for testability. Given an http response, find the rate limit reset header field and parse it. If no * header is found, wait for a reasonably amount of time.