-
Notifications
You must be signed in to change notification settings - Fork 48
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
Issue #50: HTTP errors are ignored and result in empty responses with… #55
base: master
Are you sure you want to change the base?
Conversation
…s with cache poisoning. WARNING This change is not a drop in replacement as if we get 403 because the token is incorrect, a checked exception is raised. Also note that, if an empty or null token is passed, it is now a fail fast (instead of getting a null pointer exception at the first request)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tdltdl thanks for sending your PR. I will continue to bring timely feedback from now on so we can create new package versions after each PR.
Please go over the exception restructuring suggested, with all HTTP exceptions inheriting from HttpErrorException
. That includes simplifying all throws
clauses to throws HttpErrorException
where it makes sense.
Could you also update README.md
' s Error section and document the new errors hierarchically?
I'll help you update the documentation for every exception after your next change.
@@ -374,6 +375,9 @@ public Builder setCache(Cache cache) { | |||
} | |||
|
|||
public IPinfo build() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this have throws IllegalArgumentException
?
* <p>That likely indicates that the token is either missing, incorrect or expired. | ||
* It is a checked exception so, if you have multiple tokens (example during transition), you can fall back to another token.</p> | ||
*/ | ||
public class InvalidTokenException extends Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we've introduced a proper HttpErrorException
class, we should have InvalidTokenException
and RateLimitedException
also inherit from it, as they are technically exceptions stemming from an HTTP error response.
This helps simplify the design (no need to disambiguate everywhere with throws RateLimitedException, InvalidTokenException
) and it also helps clarify (in code) that they stem from the same source.
@@ -18,9 +17,9 @@ protected BaseRequest(OkHttpClient client, String token) { | |||
this.token = token; | |||
} | |||
|
|||
public abstract T handle() throws RateLimitedException; | |||
public abstract T handle() throws RateLimitedException, InvalidTokenException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to throws HttpErrorException
|
||
public Response handleRequest(Request.Builder request) throws RateLimitedException { | ||
public Response handleRequest(Request.Builder request) throws RateLimitedException, InvalidTokenException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, this can be simplified throws HttpErrorException
… cache poisoning.
WARNING This change is not a drop in replacement as if we get 403 because the token is incorrect, a checked exception is raised.
Also note that, if an empty or null token is passed, it is now a fail fast (instead of getting a null pointer exception at the first request)