From 46ae58d6af07fbf9ca91556334af86aa639ef669 Mon Sep 17 00:00:00 2001 From: Patrick Huck Date: Fri, 12 Feb 2021 22:50:57 -0800 Subject: [PATCH] portal: catch not found exceptions --- mpcontribs-portal/mpcontribs/portal/views.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mpcontribs-portal/mpcontribs/portal/views.py b/mpcontribs-portal/mpcontribs/portal/views.py index 8b2c2bd45..3096d4c7e 100644 --- a/mpcontribs-portal/mpcontribs/portal/views.py +++ b/mpcontribs-portal/mpcontribs/portal/views.py @@ -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" @@ -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())