diff --git a/CHANGELOG.md b/CHANGELOG.md index 4314a429..ef6b6089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Release Notes for Campaign ## 2.8.3 - Unreleased +### Changed +- Logged messages now include the event that was passed into a webhook when a failure is encountered ([#398](https://github.com/putyourlightson/craft-campaign/issues/398)). + ### Fixed Fixed a bug that was causing errors when updating search indexes when a sendout’s subject was not set ([#397](https://github.com/putyourlightson/craft-campaign/issues/397)). diff --git a/src/controllers/WebhookController.php b/src/controllers/WebhookController.php index 02335d9b..1a0efd07 100755 --- a/src/controllers/WebhookController.php +++ b/src/controllers/WebhookController.php @@ -105,9 +105,11 @@ public function actionAmazonSes(): ?Response $email = $body['bounce']['bouncedRecipients'][0]['emailAddress']; return $this->_callWebhook('bounced', $email); } + + return $this->_asRawFailure('Event `' . ($eventType ?? '') . '` not found.'); } - return $this->_asRawFailure('Event not found.'); + return $this->_asRawFailure('No event provided.'); } /** @@ -173,7 +175,11 @@ public function actionMailgun(): ?Response return $this->_callWebhook('bounced', $email); } - return $this->_asRawFailure('Event not found.'); + if ($event) { + return $this->_asRawFailure('Event `' . $event . '` not found.'); + } + + return $this->_asRawFailure('No event provided.'); } /** @@ -198,9 +204,13 @@ public function actionMandrill(): ?Response return $this->_callWebhook('bounced', $email); } } + + $eventTypes = array_filter(array_map(fn($event) => $event['event'] ?? null, $events)); + + return $this->_asRawFailure('Event `' . implode(', ', $eventTypes) . '` not found.'); } - return $this->_asRawFailure('Event not found.'); + return $this->_asRawFailure('No event provided.'); } /** @@ -250,7 +260,11 @@ public function actionPostmark(): ?Response } } - return $this->_asRawFailure('Event not found.'); + if ($eventType) { + return $this->_asRawFailure('Event `' . $eventType . '` not found.'); + } + + return $this->_asRawFailure('No event provided.'); } /** @@ -278,9 +292,13 @@ public function actionSendgrid(): ?Response return $this->_callWebhook('bounced', $email); } } + + $eventTypes = array_filter(array_map(fn($event) => $event['event'] ?? null, $events)); + + return $this->_asRawFailure('Event `' . implode(', ', $eventTypes) . '` not found.'); } - return $this->_asRawFailure('Event not found.'); + return $this->_asRawFailure('No event provided.'); } /** @@ -291,7 +309,7 @@ private function _callWebhook(string $event, string $email = null): Response Campaign::$plugin->log('Webhook request: ' . $this->request->getRawBody(), [], Logger::LEVEL_WARNING); if ($email === null) { - return $this->_asRawFailure('Email not found.'); + return $this->_asRawFailure('No email provided.'); } $contact = Campaign::$plugin->contacts->getContactByEmail($email);