Skip to content

Commit

Permalink
portal: catch not found exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Feb 13, 2021
1 parent 4122599 commit 46ae58d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions mpcontribs-portal/mpcontribs/portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,12 @@ def contribution(request, cid):
return render(request, "contribution.html", ctx.flatten())

client = Client(**ckwargs)
contrib = client.contributions.get_entry(
pk=cid, _fields=["identifier", "notebook"]
).result()
try:
contrib = client.contributions.get_entry(
pk=cid, _fields=["identifier", "notebook"]
).result()
except HTTPNotFound:
return HttpResponse(f"Contribution {cid} not found.", status=404)

if "notebook" not in contrib:
url = f"{client.url}/notebooks/build"
Expand All @@ -205,7 +208,11 @@ def contribution(request, cid):
return render(request, "contribution.html", ctx.flatten())

nid = contrib["notebook"]
nb = client.notebooks.get_entry(pk=nid, _fields=["_all"]).result()
try:
nb = client.notebooks.get_entry(pk=nid, _fields=["_all"]).result()
except HTTPNotFound:
return HttpResponse(f"Notebook {nid} not found.", status=404)

ctx["identifier"], ctx["cid"] = contrib["identifier"], cid
ctx["nb"], _ = export_notebook(nb, cid)
return render(request, "contribution.html", ctx.flatten())
Expand Down

0 comments on commit 46ae58d

Please sign in to comment.