forked from ipinfo/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue ipinfo#50: HTTP errors are ignored and result in empty response…
…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)
- Loading branch information
Thierry De Leeuw
committed
Sep 11, 2024
1 parent
32b6aac
commit 1472eb0
Showing
10 changed files
with
77 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/io/ipinfo/api/errors/ClientErrorException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.ipinfo.api.errors; | ||
|
||
/** | ||
* <p>This exception is raised when a client error is occurring (Http status code like 4xx).</p> | ||
* | ||
* <p>Note that HTTP status 403 (Forbidden) is now reported as a checked exception of type @see InvalidTokenException .</p> | ||
*/ | ||
public class ClientErrorException extends HttpErrorException { | ||
public ClientErrorException(int statusCode, String message) { | ||
super(statusCode, message); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/io/ipinfo/api/errors/HttpErrorException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.ipinfo.api.errors; | ||
|
||
/** | ||
* This covers all non 403 and 429 Http error statuses. | ||
*/ | ||
public class HttpErrorException extends RuntimeException { | ||
private final int statusCode; | ||
|
||
public HttpErrorException(int statusCode, String message) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/io/ipinfo/api/errors/InvalidTokenException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.ipinfo.api.errors; | ||
|
||
/** | ||
* <p>This exception is raised when the service returns a 403 (access denied).</p> | ||
* | ||
* <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 { | ||
public InvalidTokenException() { | ||
super("The server did not accepted the provided token or no token was provided."); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/io/ipinfo/api/errors/ServerErrorException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.ipinfo.api.errors; | ||
|
||
/** | ||
* This exception is raised when a server error is returned by IpInfo (Http status like 5xx) | ||
*/ | ||
public class ServerErrorException extends HttpErrorException { | ||
public ServerErrorException(int statusCode, String message) { | ||
super(statusCode, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters