From c8ccd89af2b293c4ac5132f37ec7c5901d78fc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 11 Feb 2020 09:55:30 +0200 Subject: [PATCH] In hc.front.views.ping_details, if a ping does not exist, return a friendly message --- CHANGELOG.md | 2 +- hc/front/tests/test_ping_details.py | 2 +- hc/front/views.py | 2 +- templates/front/ping_details_not_found.html | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 templates/front/ping_details_not_found.html diff --git a/CHANGELOG.md b/CHANGELOG.md index b4f76165..1135be00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +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 +- In hc.front.views.ping_details, if a ping does not exist, return a friendly message ## 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 3177a48b..6761daf8 100644 --- a/hc/front/tests/test_ping_details.py +++ b/hc/front/tests/test_ping_details.py @@ -58,4 +58,4 @@ class LastPingTestCase(BaseTestCase): 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) + self.assertContains(r, "No additional information is", status_code=200) diff --git a/hc/front/views.py b/hc/front/views.py index 1a89b925..ac052302 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -427,7 +427,7 @@ def ping_details(request, code, n=None): try: ping = q.latest("created") except Ping.DoesNotExist: - raise Http404("not found") + return render(request, "front/ping_details_not_found.html") ctx = {"check": check, "ping": ping} diff --git a/templates/front/ping_details_not_found.html b/templates/front/ping_details_not_found.html new file mode 100644 index 00000000..80fc3ebd --- /dev/null +++ b/templates/front/ping_details_not_found.html @@ -0,0 +1,4 @@ +