Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tdltdl
Copy link

@tdltdl tdltdl commented Sep 11, 2024

… 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)

…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)
Copy link
Contributor

@max-ipinfo max-ipinfo left a 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() {
Copy link
Contributor

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 {
Copy link
Contributor

@max-ipinfo max-ipinfo Feb 22, 2025

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;
Copy link
Contributor

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 {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants