Loading src/Event/SendErrorEvent.php 0 → 100644 +87 −0 Original line number Diff line number Diff line <?php namespace Drupal\webhooks\Event; use Drupal\webhooks\Entity\WebhookConfig; use Drupal\webhooks\Webhook; use Symfony\Component\EventDispatcher\Event; /** * Class Send Event. * * @package Drupal\webhooks\Event */ class SendErrorEvent extends Event { /** * The webhook. * * @var \Drupal\webhooks\Webhook */ protected $webhook; /** * The webhook configuration. * * @var \Drupal\webhooks\Entity\WebhookConfig */ protected $webhookConfig; /** * The error. * * @var \Exception */ protected $e; /** * SendEvent constructor. * * @param \Drupal\webhooks\Entity\WebhookConfig $webhook_config * A webhook configuration entity. * @param \Drupal\webhooks\Webhook $webhook * A webhook. * @param \Exception $e * An error. */ public function __construct( WebhookConfig $webhook_config, Webhook $webhook, \Exception $e ) { $this->webhookConfig = $webhook_config; $this->webhook = $webhook; $this->e = $e; } /** * Get the webhooks. * * @return \Drupal\webhooks\Webhook * A webhook. */ public function getWebhook() { return $this->webhook; } /** * Get the webhook configuration. * * @return \Drupal\webhooks\Entity\WebhookConfig * A webhook configuration. */ public function getWebhookConfig() { return $this->webhookConfig; } /** * Get the error. * * @return \Exception * An error. */ public function getError() { return $this->e; } } src/Event/WebhookEvents.php +12 −0 Original line number Diff line number Diff line Loading @@ -32,4 +32,16 @@ final class WebhookEvents { */ const RECEIVE = 'webhook.receive'; /** * Name of the event fired when a webhook send error is sent. * * This event allows modules to perform an action whenever a webhook send * error appears. * The event listener method receives a \Drupal\webhooks\Event\SendErrorEvent * instance. * * @Event */ const SEND_ERROR = 'webhook.send.error'; } src/WebhooksService.php +7 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use Drupal\webhooks\Entity\WebhookConfig; use Drupal\webhooks\Event\WebhookEvents; use Drupal\webhooks\Event\ReceiveEvent; use Drupal\webhooks\Event\SendEvent; use Drupal\webhooks\Event\SendErrorEvent; use Drupal\webhooks\Exception\WebhookIncomingEndpointNotFoundException; use GuzzleHttp\Client; use Symfony\Component\EventDispatcher\EventDispatcherInterface; Loading Loading @@ -199,6 +200,12 @@ class WebhooksService implements WebhookDispatcherInterface, WebhookReceiverInte ); } catch (\Exception $e) { // Dispatch Webhook Send error event. $this->eventDispatcher->dispatch( WebhookEvents::SEND_ERROR, new SendErrorEvent($webhook_config, $webhook, $e) ); $this->logger->error( 'Dispatch Failed. Subscriber %subscriber on Webhook %uuid for Event %event: @message', [ '%subscriber' => $webhook_config->id(), Loading Loading
src/Event/SendErrorEvent.php 0 → 100644 +87 −0 Original line number Diff line number Diff line <?php namespace Drupal\webhooks\Event; use Drupal\webhooks\Entity\WebhookConfig; use Drupal\webhooks\Webhook; use Symfony\Component\EventDispatcher\Event; /** * Class Send Event. * * @package Drupal\webhooks\Event */ class SendErrorEvent extends Event { /** * The webhook. * * @var \Drupal\webhooks\Webhook */ protected $webhook; /** * The webhook configuration. * * @var \Drupal\webhooks\Entity\WebhookConfig */ protected $webhookConfig; /** * The error. * * @var \Exception */ protected $e; /** * SendEvent constructor. * * @param \Drupal\webhooks\Entity\WebhookConfig $webhook_config * A webhook configuration entity. * @param \Drupal\webhooks\Webhook $webhook * A webhook. * @param \Exception $e * An error. */ public function __construct( WebhookConfig $webhook_config, Webhook $webhook, \Exception $e ) { $this->webhookConfig = $webhook_config; $this->webhook = $webhook; $this->e = $e; } /** * Get the webhooks. * * @return \Drupal\webhooks\Webhook * A webhook. */ public function getWebhook() { return $this->webhook; } /** * Get the webhook configuration. * * @return \Drupal\webhooks\Entity\WebhookConfig * A webhook configuration. */ public function getWebhookConfig() { return $this->webhookConfig; } /** * Get the error. * * @return \Exception * An error. */ public function getError() { return $this->e; } }
src/Event/WebhookEvents.php +12 −0 Original line number Diff line number Diff line Loading @@ -32,4 +32,16 @@ final class WebhookEvents { */ const RECEIVE = 'webhook.receive'; /** * Name of the event fired when a webhook send error is sent. * * This event allows modules to perform an action whenever a webhook send * error appears. * The event listener method receives a \Drupal\webhooks\Event\SendErrorEvent * instance. * * @Event */ const SEND_ERROR = 'webhook.send.error'; }
src/WebhooksService.php +7 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use Drupal\webhooks\Entity\WebhookConfig; use Drupal\webhooks\Event\WebhookEvents; use Drupal\webhooks\Event\ReceiveEvent; use Drupal\webhooks\Event\SendEvent; use Drupal\webhooks\Event\SendErrorEvent; use Drupal\webhooks\Exception\WebhookIncomingEndpointNotFoundException; use GuzzleHttp\Client; use Symfony\Component\EventDispatcher\EventDispatcherInterface; Loading Loading @@ -199,6 +200,12 @@ class WebhooksService implements WebhookDispatcherInterface, WebhookReceiverInte ); } catch (\Exception $e) { // Dispatch Webhook Send error event. $this->eventDispatcher->dispatch( WebhookEvents::SEND_ERROR, new SendErrorEvent($webhook_config, $webhook, $e) ); $this->logger->error( 'Dispatch Failed. Subscriber %subscriber on Webhook %uuid for Event %event: @message', [ '%subscriber' => $webhook_config->id(), Loading