Browse Source

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

pull/328/head
Pēteris Caune 5 years ago
parent
commit
b0b6ee3149
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 12 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +7
    -0
      hc/front/tests/test_ping_details.py
  3. +4
    -1
      hc/front/views.py

+ 1
- 0
CHANGELOG.md 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 - Don't trigger "down" notifications when changing schedule interactively in web UI
- Fix sendalerts crash loop when encountering a bad cron schedule - Fix sendalerts crash loop when encountering a bad cron schedule
- Stricter cron validation, reject schedules like "At midnight of February 31" - 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 ## v1.12.0 - 2020-01-02


+ 7
- 0
hc/front/tests/test_ping_details.py View File

@ -52,3 +52,10 @@ class LastPingTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.get("/checks/%s/last_ping/" % check.code) r = self.client.get("/checks/%s/last_ping/" % check.code)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
def test_it_handles_missing_ping(self):
check = Check.objects.create(project=self.project)
self.client.login(username="[email protected]", password="password")
r = self.client.get("/checks/%s/pings/123/" % check.code)
self.assertEqual(r.status_code, 404)

+ 4
- 1
hc/front/views.py View File

@ -424,7 +424,10 @@ def ping_details(request, code, n=None):
if n: if n:
q = q.filter(n=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} ctx = {"check": check, "ping": ping}


Loading…
Cancel
Save