refactor: SendDomainEventNotif only if the domain name exists

This commit is contained in:
Maël Gangloff
2024-08-27 00:48:42 +02:00
parent 63deca2ba1
commit be57269282

View File

@@ -19,6 +19,10 @@ use Symfony\Component\Messenger\Exception\ExceptionInterface;
use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Address;
use Symfony\Component\Notifier\Recipient\Recipient; 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] #[AsMessageHandler]
final readonly class UpdateDomainsFromWatchlistHandler final readonly class UpdateDomainsFromWatchlistHandler
@@ -38,9 +42,15 @@ final readonly class UpdateDomainsFromWatchlistHandler
} }
/** /**
* @throws TransportExceptionInterface * @param UpdateDomainsFromWatchlist $message
* @throws \Exception
* @throws ExceptionInterface * @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 public function __invoke(UpdateDomainsFromWatchlist $message): void
{ {
@@ -63,6 +73,7 @@ final readonly class UpdateDomainsFromWatchlistHandler
try { try {
$this->RDAPService->registerDomain($domain->getLdhName()); $this->RDAPService->registerDomain($domain->getLdhName());
$this->bus->dispatch(new SendDomainEventNotif($watchList->getToken(), $domain->getLdhName(), $updatedAt));
} catch (NotFoundHttpException) { } catch (NotFoundHttpException) {
if (null !== $watchList->getConnector()) { if (null !== $watchList->getConnector()) {
$this->bus->dispatch(new OrderDomain($watchList->getToken(), $domain->getLdhName(), $updatedAt)); $this->bus->dispatch(new OrderDomain($watchList->getToken(), $domain->getLdhName(), $updatedAt));
@@ -75,9 +86,9 @@ final readonly class UpdateDomainsFromWatchlistHandler
$email = (new DomainUpdateErrorNotification($this->sender, $domain)) $email = (new DomainUpdateErrorNotification($this->sender, $domain))
->asEmailMessage(new Recipient($watchList->getUser()->getEmail())); ->asEmailMessage(new Recipient($watchList->getUser()->getEmail()));
$this->mailer->send($email->getMessage()); $this->mailer->send($email->getMessage());
}
$this->bus->dispatch(new SendDomainEventNotif($watchList->getToken(), $domain->getLdhName(), $updatedAt)); throw $e;
}
} }
} }
} }