Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,44 @@ public enum Cause {
}

private String message;
private final Integer statusCode;
Copy link
Owner

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? 🤔

Copy link
Author

@Fugasss Fugasss May 25, 2025

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.

Copy link
Owner

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.


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) {
Copy link
Owner

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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 + ").";
Expand All @@ -58,4 +70,8 @@ public String getMessage() {
return this.message;
}
}

public Integer getStatusCode() {
return statusCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class SteamApiKeyException extends SteamApiException {
private static final long serialVersionUID = 5154813503049374498L;

public SteamApiKeyException(String message) {
super(message);
super(message, 400);
}
}