Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/main/java/org/kohsuke/github/GitHubAbuseLimitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
*
Expand All @@ -100,15 +111,4 @@ private boolean isServiceDown(GitHubConnectorResponse connectorResponse) throws
* @see <a href="https://developer.github.com/v3/#rate-limiting">API documentation from GitHub</a>
*/
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;
}
30 changes: 15 additions & 15 deletions src/main/java/org/kohsuke/github/GitHubRateLimitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
Expand Down
Loading