Skip to content

Commit 787c79e

Browse files
authored
Add handling for stray BadQueryErrors (#252)
1 parent 3da0cf6 commit 787c79e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

profiles/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,13 @@ def home(info=None):
8989
@auth.oidc_auth("default")
9090
@before_request
9191
def user(uid=None, info=None):
92-
return render_template("profile.html", info=info, member_info=get_member_info(uid))
92+
try:
93+
return render_template("profile.html", info=info, member_info=get_member_info(uid))
94+
except BadQueryError as bqe:
95+
# ldap_get_member() returns a BadQueryError if getting the user's information fails.
96+
# Flask already treats a stray BadQueryError as a 404, but actually handling it prevents the traceback
97+
# from getting dumped into the log.
98+
return render_template("404.html", message=bqe), 404
9399

94100

95101
@app.route("/results", methods=["POST"])
@@ -172,7 +178,10 @@ def logout():
172178

173179
@app.route("/image/<uid>", methods=["GET"])
174180
def image(uid):
175-
return get_image(uid)
181+
try:
182+
return get_image(uid)
183+
except BadQueryError as bqe:
184+
return render_template("404.html", message=bqe), 404
176185

177186

178187
@app.route("/clearcache")

0 commit comments

Comments
 (0)