Browse Source

Error handling stuff

master^2
TGRCDev 4 months ago
parent
commit
e8a48d24f5
No known key found for this signature in database GPG Key ID: 3A975199085322C3
5 changed files with 77 additions and 16 deletions
  1. +41
    -11
      __init__.py
  2. +9
    -0
      lib/wcwp_rust/src/python.rs
  3. +3
    -1
      lib/wcwp_rust/src/steam.rs
  4. +19
    -4
      static/scripts/app.js
  5. +5
    -0
      static/styles/app.css

+ 41
- 11
__init__.py View File

@ -258,7 +258,7 @@ def create_app():
errcode, steam_info = fetch_steam_cookie(request)
if "steam_id" not in steam_info.keys():
return (
{"message": "Not signed in to Steam", "errcode": -1},
"Not signed in to Steam. Please refresh the page.",
403
)
@ -275,31 +275,40 @@ def create_app():
return jsonify(friends_info)
except wcwp.steam.BadWebkeyException:
traceback.print_exc()
return (
json.dumps({"message": "Site has bad Steam API key. Please contact us about this error at " + contact_email, "errcode": -1}),
"Site has bad Steam API key. Please contact us about this error at " + contact_email,
500
)
except wcwp.steam.ServerError:
except wcwp.steam.ServerErrorException:
traceback.print_exc()
return (
json.dumps({"message": "Steam had an internal server error. Please try again later.", "errcode": -1}),
"Steam had an internal server error. Please try again later.",
500
)
except wcwp.steam.BadResponse:
except wcwp.steam.BadResponseException:
traceback.print_exc()
return (
json.dumps({"message": "Steam returned an unparseable response. Please try again later.", "errcode": -1}),
"Steam returned an unparseable response. Please try again later.",
500
)
except wcwp.steam.FriendListPrivateException:
traceback.print_exc()
return (
"WhatCanWePlay cannot retrieve your friend list. Please change your friend list visibility to public and refresh the page.",
500
)
except Exception:
traceback.print_exc()
if debug:
return (
json.dumps({"message": traceback.format_exc(), "errcode": -1}),
traceback.format_exc(),
500
)
else:
traceback.print_exc()
return (
json.dumps({"message": "An unknown error has occurred. Please try again later.", "errcode": -1}),
"An unknown error has occurred. Please try again later.",
500
)
@ -534,20 +543,41 @@ def create_app():
"errcode": 0
})
except wcwp.steam.BadWebkeyException:
traceback.print_exc()
return (
json.dumps({"message": "Site has bad Steam API key. Please contact us about this error at " + contact_email, "errcode": -1}),
500
)
except wcwp.steam.ServerError:
except wcwp.steam.ServerErrorException:
traceback.print_exc()
return (
json.dumps({"message": "Steam had an internal server error. Please try again later.", "errcode": -1}),
500
)
except wcwp.steam.BadResponse:
except wcwp.steam.BadResponseException:
traceback.print_exc()
return (
json.dumps({"message": "Steam returned an unparseable response. Please try again later.", "errcode": -1}),
500
)
except wcwp.steam.GamesListPrivateException as e:
if debug:
print(e)
else:
print("Intersection interrupted due to private games list")
return (
json.dumps({"errcode": 1, "user": str(e.args[1])}),
500
)
except wcwp.steam.GamesListEmptyException as e:
if debug:
print(e)
else:
print("Intersection interrupted due to private games list")
return (
json.dumps({"errcode": 2, "user": str(e.args[1])}),
500
)
except Exception:
traceback.print_exc()
if debug:
@ -557,7 +587,7 @@ def create_app():
)
else:
return (
json.dumps({"message": "An unknown error has occurred", "errcode": -1}),
json.dumps({"message": "An unknown error has occurred. Please try again later.", "errcode": -1}),
500
)

+ 9
- 0
lib/wcwp_rust/src/python.rs View File

@ -175,6 +175,9 @@ pub mod steam_exceptions {
create_exception!(steam, ServerErrorException, SteamException);
create_exception!(steam, BadResponseException, SteamException);
create_exception!(steam, BadWebkeyException, SteamException);
create_exception!(steam, GamesListPrivateException, SteamException);
create_exception!(steam, GamesListEmptyException, SteamException);
create_exception!(steam, FriendListPrivateException, SteamException);
impl From<SteamError> for PyErr {
fn from(e: SteamError) -> PyErr {
@ -182,6 +185,9 @@ pub mod steam_exceptions {
SteamError::ServerError => ServerErrorException::new_err(e.to_string()),
SteamError::BadResponse => BadResponseException::new_err(e.to_string()),
SteamError::BadWebkey => BadWebkeyException::new_err(e.to_string()),
SteamError::FriendListPrivate => FriendListPrivateException::new_err(e.to_string()),
SteamError::GamesListPrivate(steamid) => GamesListPrivateException::new_err((e.to_string(), steamid)),
SteamError::GamesListEmpty(steamid) => GamesListEmptyException::new_err((e.to_string(), steamid)),
_ => UnknownErrorException::new_err(e.to_string()),
}
}
@ -258,6 +264,9 @@ fn steam_mod(py: &Python, m: &PyModule) -> PyResult<()> {
expose_exception!(py, m, ServerErrorException)?;
expose_exception!(py, m, BadResponseException)?;
expose_exception!(py, m, BadWebkeyException)?;
expose_exception!(py, m, FriendListPrivateException)?;
expose_exception!(py, m, GamesListEmptyException)?;
expose_exception!(py, m, GamesListPrivateException)?;
return Ok(());
}


+ 3
- 1
lib/wcwp_rust/src/steam.rs View File

@ -139,6 +139,7 @@ pub fn get_steam_users_info(webkey: &str, steamids: &[u64]) -> Result<Vec<SteamU
pub fn get_owned_steam_games(webkey: &str, steamid: u64) -> Result<HashSet<u64>, SteamError> {
let base_url = Url::parse(API_URL).unwrap();
let client = reqwest::blocking::Client::new();
let response = client.get(base_url.join("IPlayerService/GetOwnedGames/v0001/").unwrap())
.query(&[
("key", webkey),
@ -229,7 +230,8 @@ pub fn get_friend_list(webkey: &str, steamid: u64) -> Result<Vec<SteamUser>, Ste
return Err(SteamError::FriendListPrivate);
}
let friendslist = &response_json["friends"];
let friendslist = &friendslist["friends"];
let mut user_ids = Vec::new();
if let Some(friendslist) = friendslist.as_array()


+ 19
- 4
static/scripts/app.js View File

@ -36,6 +36,8 @@ var current_slide_timeout;
var fetching = false;
var main_user_id = 0;
window.addEventListener("load", function() {
submit = document.getElementById("submit-button");
submit.addEventListener("click", submitButtonClicked);
@ -72,6 +74,8 @@ window.addEventListener("load", function() {
}
}
var main_user_info = {}
for(var i = 0; i < main_user.children.length; i++)
{
var child = main_user.children[i];
@ -89,8 +93,19 @@ window.addEventListener("load", function() {
else
{
userCheckboxClicked(child);
main_user_id = child.dataset.steamId;
main_user_info["steam_id"] = main_user_id;
}
}
else if(child.className == "user-name")
{
main_user_info["screen_name"] = child.children[0].innerText;
}
}
if(main_user_id != 0)
{
user_info[main_user_id] = main_user_info
}
// Fetch friends list
@ -174,16 +189,16 @@ function submitButtonClicked()
function intersectResponse(data) {
if(data["errcode"] == 1)
{ // User has non-visible games list
displayError("WhatCanWePlay cannot access the games list of " + user_info[data["user"]]["screen_name"] + ". This either means that their Game details visibility is not Public, or they are being rate-limited by Steam for having too many requests. You can try one of the following fixes:\
<br><br>- Ask " + user_info[data["user"]]["screen_name"] + " to set their Game details to Public\
<br>- Remove " + user_info[data["user"]]["screen_name"] + " from your selected users\
displayError("WhatCanWePlay cannot access the games list of <span class='err-user-name'>" + user_info[data["user"]]["screen_name"] + "</span>. This either means that their Game details visibility is not Public, or they are being rate-limited by Steam for having too many requests. You can try one of the following fixes:\
<br><br>- Ask <span class='err-user-name'>" + user_info[data["user"]]["screen_name"] + "</span> to set their Game details to Public\
<br>- Remove <span class='err-user-name'>" + user_info[data["user"]]["screen_name"] + "</span> from your selected users\
<br>- Try again later\
");
return;
}
else if(data["errcode"] == 2)
{ // User has empty games list
displayError(user_info[data["user"]]["screen_name"] + " has an empty games list, and cannot possibly share any common games with the selected users. Please deselect " + user_infp[data["user"]]["screen_name"] + " and try again.")
displayError("<span class='err-user-name'>" + user_info[data["user"]]["screen_name"] + "</span> has an empty games list, and cannot possibly share any common games with the selected users. Please deselect <span class='err-user-name'>" + user_info[data["user"]]["screen_name"] + "</span> and try again.")
return;
}
else if(data["errcode"] != 0)


+ 5
- 0
static/styles/app.css View File

@ -306,6 +306,11 @@ html, body {
color: goldenrod;
}
.err-user-name {
font-style: italic;
font-size: larger;
}
/* Desktop Overrides */
@media (min-width: 601px) {
#app {


Loading…
Cancel
Save