-
Notifications
You must be signed in to change notification settings - Fork 18
SteamApiException's status code exposure #53
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,32 +9,44 @@ public enum Cause { | |
} | ||
|
||
private String message; | ||
private final Integer statusCode; | ||
|
||
public SteamApiException(String message) { | ||
super(message); | ||
this.statusCode = 500; | ||
} | ||
|
||
public SteamApiException(String message, Throwable cause) { | ||
super(message, cause); | ||
this.statusCode = 500; | ||
} | ||
|
||
public SteamApiException(String message, Integer statusCode) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
} | ||
|
||
public SteamApiException(Cause cause, Throwable exceptionCause) { | ||
|
||
super(exceptionCause); | ||
|
||
switch (cause) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to add the other causes here as well, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is possible to add causes for the most frequent cases: 400, 401, 403, 404, 429, 500, 503. What do you think about these cases? |
||
case MAPPING: | ||
this.statusCode = 400; | ||
this.message = "The JSON response could not be parsed or mapped to the designated POJO. The most likely cause for this is that" | ||
+ " the Steam API itself changed. Check for newer versions of this library to compensate for this."; | ||
break; | ||
default: | ||
this.statusCode = 500; | ||
this.message = "The Web API request failed due to an unexpected error: " | ||
+ exceptionCause.getMessage(); | ||
} | ||
} | ||
|
||
public SteamApiException(Cause cause, Integer statusCode) { | ||
|
||
this.statusCode = statusCode; | ||
|
||
switch (cause) { | ||
case HTTP_ERROR: | ||
this.message = "The Web API request failed (status code: " + statusCode + ")."; | ||
|
@@ -58,4 +70,8 @@ public String getMessage() { | |
return this.message; | ||
} | ||
} | ||
|
||
public Integer getStatusCode() { | ||
return statusCode; | ||
} | ||
} |
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.
As there are a few cases where it is possible that the Exception is created and there is no HTTP Error Code to associate with (see for example SteamWebApiRequestHandler#59), perhaps it would be best to make this into a
private final Optional<Integer> statusCode
? What do you think? 🤔Uh oh!
There was an error while loading. Please reload this page.
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.
I think it would be more appropriate to use IllegalArgumentException than SteamApiException(SteamWebApiRequestHandler#59), because it clearly indicates that the wrong argument is passed. In my opinion, SteamApiException should be used only in the cases of interaction with the steam api - for example, we made a request and got 429 Too Many Requests. So there will be no way, when the status code will be null.
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.
Hmmm you might be right. I will try to get around to make the changes you suggest, however this will have to wait until after I return from my vacation beginning tomorrow so expect it no earlier than sometime in June. Hope that's ok with you.