From b0b6ee3149720c3c83de26d747ed5896486d235a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 11 Feb 2020 09:44:02 +0200 Subject: [PATCH] In hc.front.views.ping_details, if a ping does not exist, return 404 instead of 500 --- CHANGELOG.md | 1 + hc/front/tests/test_ping_details.py | 7 +++++++ hc/front/views.py | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78dc806e..b4f76165 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file. - Don't trigger "down" notifications when changing schedule interactively in web UI - Fix sendalerts crash loop when encountering a bad cron schedule - Stricter cron validation, reject schedules like "At midnight of February 31" +- In hc.front.views.ping_details, if a ping does not exist, return 404 instead of 500 ## v1.12.0 - 2020-01-02 diff --git a/hc/front/tests/test_ping_details.py b/hc/front/tests/test_ping_details.py index 77f5d965..3177a48b 100644 --- a/hc/front/tests/test_ping_details.py +++ b/hc/front/tests/test_ping_details.py @@ -52,3 +52,10 @@ class LastPingTestCase(BaseTestCase): self.client.login(username="bob@example.org", password="password") r = self.client.get("/checks/%s/last_ping/" % check.code) self.assertEqual(r.status_code, 200) + + def test_it_handles_missing_ping(self): + check = Check.objects.create(project=self.project) + + self.client.login(username="alice@example.org", password="password") + r = self.client.get("/checks/%s/pings/123/" % check.code) + self.assertEqual(r.status_code, 404) diff --git a/hc/front/views.py b/hc/front/views.py index 926c4c01..1a89b925 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -424,7 +424,10 @@ def ping_details(request, code, n=None): if n: q = q.filter(n=n) - ping = q.latest("created") + try: + ping = q.latest("created") + except Ping.DoesNotExist: + raise Http404("not found") ctx = {"check": check, "ping": ping}