diff --git a/hc/api/tests/test_ping.py b/hc/api/tests/test_ping.py index 91c1bcf7..bd2b6d31 100644 --- a/hc/api/tests/test_ping.py +++ b/hc/api/tests/test_ping.py @@ -76,6 +76,7 @@ class PingTestCase(BaseTestCase): def test_it_handles_missing_check(self): r = self.client.get("/ping/07c2f548-9850-4b27-af5d-6c9dc157ec02/") self.assertEqual(r.status_code, 404) + self.assertEqual(r.content.decode(), "not found") def test_it_handles_120_char_ua(self): ua = ( diff --git a/hc/api/tests/test_ping_by_slug.py b/hc/api/tests/test_ping_by_slug.py index 92d49f0e..27e4a136 100644 --- a/hc/api/tests/test_ping_by_slug.py +++ b/hc/api/tests/test_ping_by_slug.py @@ -35,6 +35,7 @@ class PingBySlugTestCase(BaseTestCase): def test_it_handles_missing_check(self): r = self.client.get(f"/ping/{self.project.ping_key}/bar") self.assertEqual(r.status_code, 404) + self.assertEqual(r.content.decode(), "not found") def test_it_never_caches(self): r = self.client.get(self.url) diff --git a/hc/api/views.py b/hc/api/views.py index 6054dfbd..660f3f5a 100644 --- a/hc/api/views.py +++ b/hc/api/views.py @@ -33,7 +33,10 @@ class BadChannelException(Exception): @never_cache def ping(request, code, check=None, action="success", exitstatus=None): if check is None: - check = get_object_or_404(Check, code=code) + try: + check = Check.objects.get(code=code) + except Check.DoesNotExist: + return HttpResponseNotFound("not found") if exitstatus is not None and exitstatus > 255: return HttpResponseBadRequest("invalid url format") @@ -62,7 +65,9 @@ def ping(request, code, check=None, action="success", exitstatus=None): @csrf_exempt def ping_by_slug(request, ping_key, slug, action="success", exitstatus=None): try: - check = get_object_or_404(Check, slug=slug, project__ping_key=ping_key) + check = Check.objects.get(slug=slug, project__ping_key=ping_key) + except Check.DoesNotExist: + return HttpResponseNotFound("not found") except Check.MultipleObjectsReturned: return HttpResponse("ambiguous slug", status=409)