Mailjet: handle bare event when webhook "group events" not enabled

Fixes #106
This commit is contained in:
medmunds
2018-05-15 10:38:15 -07:00
parent 59a90c6895
commit 3cadaca9dd
2 changed files with 37 additions and 0 deletions

View File

@@ -16,6 +16,14 @@ class MailjetTrackingWebhookView(AnymailBaseWebhookView):
def parse_events(self, request):
esp_events = json.loads(request.body.decode('utf-8'))
# Mailjet webhook docs say the payload is "a JSON array of event objects,"
# but that's not true if "group events" isn't enabled in webhook config...
try:
esp_events[0] # is this really an array of events?
except IndexError:
pass # yep (and it's empty?!)
except KeyError:
esp_events = [esp_events] # nope, it's a single, bare event
return [self.esp_to_anymail_event(esp_event) for esp_event in esp_events]
# https://dev.mailjet.com/guides/#events