Browse Source

Fix hc.api.views.notification_status to always return 200

If the notification does not exist, or is more than a hour
old, return HTTP 200 (instead of 400 or 404) so the other
party doesn't retry over and over again.
pull/483/head
Pēteris Caune 4 years ago
parent
commit
44a677f327
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 7 additions and 8 deletions
  1. +1
    -1
      hc/api/tests/test_notification_status.py
  2. +6
    -6
      hc/api/views.py
  3. +0
    -1
      hc/front/views.py

+ 1
- 1
hc/api/tests/test_notification_status.py View File

@ -67,7 +67,7 @@ class NotificationStatusTestCase(BaseTestCase):
fake_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
url = f"/api/v1/notifications/{fake_code}/status"
r = self.client.post(url, {"MessageStatus": "failed"})
self.assertEqual(r.status_code, 404)
self.assertEqual(r.status_code, 200)
def test_it_requires_post(self):
r = self.client.get(self.url)


+ 6
- 6
hc/api/views.py View File

@ -436,12 +436,12 @@ def badge(request, badge_key, signature, tag, fmt):
def notification_status(request, code):
""" Handle notification delivery status callbacks. """
notification = get_object_or_404(Notification, code=code)
td = timezone.now() - notification.created
if td.total_seconds() > 3600:
# If the webhook is called more than 1 hour after the notification, ignore it.
# Return HTTP 200 so the other party doesn't retry over and over again:
try:
cutoff = timezone.now() - td(hours=1)
notification = Notification.objects.get(code=code, created__gt=cutoff)
except Notification.DoesNotExist:
# If the notification does not exist, or is more than a hour old,
# return HTTP 200 so the other party doesn't retry over and over again:
return HttpResponse()
error, mark_not_verified = None, False


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

@ -477,7 +477,6 @@ def cron_preview(request):
for i in range(0, 6):
ctx["dates"].append(it.get_next(datetime))
pass
except UnknownTimeZoneError:
ctx["bad_tz"] = True
except:


Loading…
Cancel
Save