-
Notifications
You must be signed in to change notification settings - Fork 764
Make isError
on GitHubConnectorResponseErrorHandler public.
#2127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make isError
on GitHubConnectorResponseErrorHandler public.
#2127
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2127 +/- ##
=========================================
Coverage 85.02% 85.02%
Complexity 2495 2495
=========================================
Files 237 237
Lines 7351 7351
Branches 388 388
=========================================
Hits 6250 6250
Misses 871 871
Partials 230 230 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
FWIW, while I'm not against this patch, I would very much in favor of making the default implementation better. As most people will just use it as is and shoot themselves in the foot. This patch might be a good way to experiment but it would be nice to contribute back a better default implementation if you come up with one! |
@gsmet The main reason for me doing this small patch is more of a preliminary one, as it is a quicker fix that enables the better implementation locally (potentially guided by some documentation), before said implementation is implemented in a future PR. I would also wonder given the usage in I am not against nixing this PR and writing the better implementation now, if it is felt that this change would lead to bad habits by the users. At least for our use case, it should be possible to do a local patch and build with that source and provide that in the mean time. |
Regarding said better implementation, as mentioned in my comment under #2009 there are two potential messages that can be returned that we can check for:
On a local branch that I had started working on, I have a method that we could extend private boolean hasRelevantErrorMessages(GitHubConnectorResponse connectorResponse) throws IOException {
String content = new String(connectorResponse.bodyStream().readAllBytes(), StandardCharsets.UTF_8).toLowerCase();
return content.contains("you have exceeded a secondary rate limit") || content.contains("you have triggered an abuse detection mechanism");
} If the general concept of this seems like an acceptable fix, I'd go on ahead with this and open a PR once I get some time 👍 |
I'm not completely sure why I made the method internal, but I think @gsmet points in the right direction. The The design is as intended, The library only support two types of error handlers externally, "abuse" and "rate limit" and the detection of these types of errors should be implemented centrally in this library not by consumers. The check for whether a certain kind of error handler should fire should be the same for all instance of that type error handler. All "abuse" error handlers should use the same "isError()", all "rate limit" error handlers should use the same "isError()". The only thing that should be implemented by consumers of the library is the what they choose to do about the error - the "onError()" method. Regarding your proposed solution with string checking: github-api/src/main/java/org/kohsuke/github/GitHubConnectorResponseErrorHandler.java Lines 74 to 79 in 40f3b4d
The check for If you want to abstract the helper that searches the first N lines for a list of strings, that's sounds good. Now that I'm thinking about it would probably be more performant to change the loop above to a something that grabs the first 2kb of the response as a string and searches that for each of the error strings, instead doing line by line You might also look at #1975 for what I think should happen in this area longer term. |
@rozza-sb |
Description
Changes the access modifier on GithubConnectorResponseErrorHandler and subclasses to public. This allows library users to overwrite what constitutes an error for the response, particularly for (secondary) rate limiting.
Relates to #2009, where GithubAbuseLimitHandler is not properly detecting secondary rate limits but users cannot manually override it while the method is package-private. Additionally, the definition of
isError
underSTATUS_HTTP_BAD_REQUEST_OR_GREATER
is public, which could imply that this should be public from the start. A future PR will do a fix to the underlying issue, but in the mean time this would allow users to implement their own fix.Before submitting a PR:
@link
JavaDoc entries to the relevant documentation on https://docs.github.com/en/rest .mvn -D enable-ci clean install site "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
locally. If this command doesn't succeed, your change will not pass CI.main
. You will create your PR from that branch.When creating a PR: