From be57269282ba853350bb3074ab2ad3a57970cdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Tue, 27 Aug 2024 00:48:42 +0200 Subject: [PATCH] refactor: SendDomainEventNotif only if the domain name exists --- .../UpdateDomainsFromWatchlistHandler.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/MessageHandler/UpdateDomainsFromWatchlistHandler.php b/src/MessageHandler/UpdateDomainsFromWatchlistHandler.php index de1aecd..5357f82 100644 --- a/src/MessageHandler/UpdateDomainsFromWatchlistHandler.php +++ b/src/MessageHandler/UpdateDomainsFromWatchlistHandler.php @@ -19,6 +19,10 @@ use Symfony\Component\Messenger\Exception\ExceptionInterface; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Mime\Address; use Symfony\Component\Notifier\Recipient\Recipient; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; +use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; #[AsMessageHandler] final readonly class UpdateDomainsFromWatchlistHandler @@ -38,9 +42,15 @@ final readonly class UpdateDomainsFromWatchlistHandler } /** - * @throws TransportExceptionInterface - * @throws \Exception + * @param UpdateDomainsFromWatchlist $message * @throws ExceptionInterface + * @throws TransportExceptionInterface + * @throws ClientExceptionInterface + * @throws DecodingExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ServerExceptionInterface + * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface + * @throws \Throwable */ public function __invoke(UpdateDomainsFromWatchlist $message): void { @@ -63,6 +73,7 @@ final readonly class UpdateDomainsFromWatchlistHandler try { $this->RDAPService->registerDomain($domain->getLdhName()); + $this->bus->dispatch(new SendDomainEventNotif($watchList->getToken(), $domain->getLdhName(), $updatedAt)); } catch (NotFoundHttpException) { if (null !== $watchList->getConnector()) { $this->bus->dispatch(new OrderDomain($watchList->getToken(), $domain->getLdhName(), $updatedAt)); @@ -75,9 +86,9 @@ final readonly class UpdateDomainsFromWatchlistHandler $email = (new DomainUpdateErrorNotification($this->sender, $domain)) ->asEmailMessage(new Recipient($watchList->getUser()->getEmail())); $this->mailer->send($email->getMessage()); - } - $this->bus->dispatch(new SendDomainEventNotif($watchList->getToken(), $domain->getLdhName(), $updatedAt)); + throw $e; + } } } }