Skip to content

Commit f886a7f

Browse files
Fix Error For Unauthorized Form Access
Fixes an error where accessing a form without having the proper authorization would cause an unexpected state and raise a 500. Closes #175. Signed-off-by: Hassan Abouelela <hassan@hassanamr.com>
1 parent 3249226 commit f886a7f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

backend/routes/forms/form.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def get(self, request: Request) -> JSONResponse:
4242
if not constants.PRODUCTION and form_id == EMPTY_FORM.id:
4343
# Empty form to help with authentication in development.
4444
return JSONResponse(EMPTY_FORM.dict(admin=False))
45-
raise
45+
return JSONResponse({"error": "not_found"}, status_code=404)
4646
except discord.UnauthorizedError:
4747
admin = False
4848

@@ -53,7 +53,11 @@ async def get(self, request: Request) -> JSONResponse:
5353
if not admin:
5454
filters["features"] = {"$in": ["OPEN", "DISCOVERABLE"]}
5555

56-
form = Form(**await request.state.db.forms.find_one(filters))
56+
form = await request.state.db.forms.find_one(filters)
57+
if not form:
58+
return JSONResponse({"error": "not_found"}, status_code=404)
59+
60+
form = Form(**form)
5761
if not admin:
5862
form = filter_unittests(form)
5963

0 commit comments

Comments
 (0)