diff --git a/src/MessageHandler/ProcessDomainTriggerHandler.php b/src/MessageHandler/ProcessDomainTriggerHandler.php index 40e191d..b937f84 100644 --- a/src/MessageHandler/ProcessDomainTriggerHandler.php +++ b/src/MessageHandler/ProcessDomainTriggerHandler.php @@ -21,6 +21,7 @@ use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Mime\Email; +use Throwable; #[AsMessageHandler] final readonly class ProcessDomainTriggerHandler @@ -54,24 +55,27 @@ final readonly class ProcessDomainTriggerHandler if ($watchListTrigger->getAction() === TriggerAction::BuyDomain) { - if ($watchListTrigger->getConnector() === null) throw new Exception('Connector is missing'); + try { + if ($watchListTrigger->getConnector() === null) throw new Exception('Connector is missing'); + $connector = $watchListTrigger->getConnector(); - $connector = $watchListTrigger->getConnector(); + if ($connector->getProvider() === ConnectorProvider::OVH) { + $ovh = new OVHConnector($connector->getAuthData()); + $isDebug = $this->kernel->isDebug(); - if ($connector->getProvider() === ConnectorProvider::OVH) { - $ovh = new OVHConnector($connector->getAuthData()); - $isDebug = $this->kernel->isDebug(); - $ovh->orderDomain( - $domain, - true, - true, - true, - $isDebug - ); - $this->sendEmailDomainOrdered($domain, $connector, $watchList->getUser()); - - } else throw new Exception("Unknown provider"); + $ovh->orderDomain( + $domain, + true, + true, + true, + $isDebug + ); + $this->sendEmailDomainOrdered($domain, $connector, $watchList->getUser()); + } else throw new Exception("Unknown provider"); + } catch (Throwable) { + $this->sendEmailDomainOrderError($domain, $watchList->getUser()); + } } /** @var DomainEvent $event */ @@ -103,6 +107,24 @@ final readonly class ProcessDomainTriggerHandler $this->mailer->send($email); } + /** + * @throws TransportExceptionInterface + */ + private function sendEmailDomainOrderError(Domain $domain, User $user): void + { + $email = (new TemplatedEmail()) + ->from($this->mailerSenderEmail) + ->to($user->getEmail()) + ->subject('An error occurred while ordering a domain name') + ->htmlTemplate('emails/errors/domain_order.html.twig') + ->locale('en') + ->context([ + "domain" => $domain + ]); + + $this->mailer->send($email); + } + /** * @throws TransportExceptionInterface */ diff --git a/templates/emails/errors/domain_order.html.twig b/templates/emails/errors/domain_order.html.twig new file mode 100644 index 0000000..2f47145 --- /dev/null +++ b/templates/emails/errors/domain_order.html.twig @@ -0,0 +1,77 @@ + + + + + Domain Watchdog Error + + +
+
+

Domain Watchdog Error

+
+
+

Hello,

+

We would like to inform you that an error occurred while ordering the following domain name:

+

Domain name: {{ domain.ldhName }}

+

Here are some possible explanations:

+ +

Thank you for your understanding,

+

Sincerely,

+

Domain Watchdog

+
+ +
+ +