In hc.front.views.ping_details, if a ping does not exist, return 404 instead of 500

This commit is contained in:
Pēteris Caune 2020-02-11 09:44:02 +02:00
parent ccd30ac239
commit b0b6ee3149
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
3 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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)

View File

@ -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}