Fixed ticket download giving 500 error

This commit is contained in:
Ed 2022-12-19 18:58:16 +01:00
parent a1a2b06f8b
commit d6a7d3a440
1 changed files with 6 additions and 9 deletions

15
app.py
View File

@ -66,10 +66,7 @@ async def welcome(request, order: Order, quota: Quotas):
if order.pending_roommates: if order.pending_roommates:
for pr in order.pending_roommates: for pr in order.pending_roommates:
if not pr: continue if not pr: continue
print(pr)
pending_roommates.append(await get_order(code=pr, insecure=True)) pending_roommates.append(await get_order(code=pr, insecure=True))
print(pending_roommates)
room_members = [] room_members = []
if order.room_id: if order.room_id:
@ -92,7 +89,7 @@ async def welcome(request, order: Order, quota: Quotas):
@app.route("/manage/download_ticket") @app.route("/manage/download_ticket")
async def download_ticket(request, order: Order, quota: Quotas): async def download_ticket(request, order: Order):
if not order: if not order:
raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!")
@ -102,11 +99,11 @@ async def download_ticket(request, order: Order, quota: Quotas):
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
res = await client.get(join(base_url, f"orders/{order.code}/download/pdf/"), headers=headers) res = await client.get(join(base_url, f"orders/{order.code}/download/pdf/"), headers=headers)
if res.status_code != 200:
raise exceptions.FileNotFound("Your ticket hasn't been generated yet. Please try later!") if res.status_code != 200:
raise exceptions.SanicException("Your ticket is still being generated. Please try again later!", status_code=res.status_code)
return raw(res.content, content_type='application/pdf')
print(res.content) return raw(res.content, content_type='application/pdf')
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0", port=8188, dev=True) app.run(host="0.0.0.0", port=8188, dev=True)