Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Commit 5d176b8

Browse files
tell user that they couldn't be found instead of generic 500
1 parent fc2a181 commit 5d176b8

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

blueprints/app_stats.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ def app_guild_stats(guildid, token, user):
5050
return render_template("simple-message.html", user=user, title="Guild Not Found", message="AlphaGameBot can't find the requested guild. Either it doesn't exist (it happens to the best of us!), or AlphaGameBot is not in that guild, yet.")
5151

5252
cursor.execute("SELECT user_level, points, messages_sent, commands_ran FROM guild_user_stats WHERE userid = %s AND guildid = %s", (user["id"], guildid))
53+
db_result = cursor.fetchone()
54+
55+
if db_result is None:
56+
return render_template("simple-message.html",
57+
title="Well... this is awkward!",
58+
message="I cannot get the information requested..."
59+
"Send a message in the Discord server, or run an AlphaGameBot command in this server."
60+
"If the problem persists, then make a GitHub issue!"), 500
61+
5362
level, points, messages_sent, commands_ran = cursor.fetchone()
5463

5564
return render_template("app/guild_user_stats.html", user=user, guild=guild, level=level, points=points, messages_sent=messages_sent, commands_ran=commands_ran)
@@ -72,9 +81,9 @@ def app_leaderboard(token, user):
7281
cursor.execute("SELECT messages_sent, commands_ran FROM user_stats WHERE userid=%s", (user["id"],))
7382
re = cursor.fetchone()
7483
if re is None:
75-
messages_sent = 0
76-
commands_ran = 0
77-
points = 0
84+
messages_sent = -1
85+
commands_ran = -1
86+
points = -1
7887
else:
7988
messages_sent, commands_ran = re
8089
points = messages_sent + commands_ran * 5

blueprints/auth_discord.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ def discord_login_callback():
3838
})
3939
j = loads(r.content)
4040
if r.status_code != 200:
41-
return Response("Error while logging in: %s" % j["error_description"] , status=500)
41+
reason = j.get("error_description", None)
42+
if not reason:
43+
reason = j.get("error", None)
44+
45+
if not reason:
46+
print(j)
47+
reason = "No idea why it failed... :/"
48+
49+
return Response("Error while logging in: %s" % reason, status=500)
4250

4351
expires = datetime.now() + timedelta(seconds=j["expires_in"])
4452

0 commit comments

Comments
 (0)