From d4fcd7fe5103c8d4a7a124824b12075d3338ee7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Sat, 10 Aug 2024 23:06:03 +0200 Subject: [PATCH] fix: process domain --- .../ProcessWatchListTriggerHandler.php | 22 +++++-------------- src/Service/RDAPService.php | 22 +++++++++---------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/MessageHandler/ProcessWatchListTriggerHandler.php b/src/MessageHandler/ProcessWatchListTriggerHandler.php index bf6d290..5e4c2f3 100644 --- a/src/MessageHandler/ProcessWatchListTriggerHandler.php +++ b/src/MessageHandler/ProcessWatchListTriggerHandler.php @@ -9,6 +9,7 @@ use App\Message\ProcessDomainTrigger; use App\Message\ProcessWatchListTrigger; use App\Repository\WatchListRepository; use App\Service\RDAPService; +use GuzzleHttp\Exception\ClientException; use Psr\Log\LoggerInterface; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\Mailer\Exception\TransportExceptionInterface; @@ -17,7 +18,6 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Messenger\Exception\ExceptionInterface; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Mime\Address; -use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; #[AsMessageHandler] final readonly class ProcessWatchListTriggerHandler @@ -60,27 +60,15 @@ final readonly class ProcessWatchListTriggerHandler try { $domain = $this->RDAPService->registerDomain($domain->getLdhName()); } catch (\Throwable $e) { - if (!($e instanceof HttpExceptionInterface)) { - continue; - } $this->logger->notice('An update error email is sent to user {username}.', [ 'username' => $watchList->getUser()->getUserIdentifier(), ]); $this->sendEmailDomainUpdateError($domain, $watchList->getUser()); - } - /* - * This code is deliberately commented to avoid unwanted side effects. - * Indeed, although it is useful and relevant to schedule a new update every day, - * there is a risk that the messages will get carried away by chain reaction. - * In theory, a new message chain would be generated every week. - * - * if ($this->RDAPService::isToBeWatchClosely($domain, $updatedAt)) { - * $this->bus->dispatch(new ProcessWatchListTrigger($message->watchListToken), [ - * new DelayStamp(24 * 60 * 60 * 1e3) - * ]); - * } - */ + if (!($e instanceof ClientException)) { + continue; + } + } $this->bus->dispatch(new ProcessDomainTrigger($watchList->getToken(), $domain->getLdhName(), $updatedAt)); } diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index e006fd0..60a6126 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -165,18 +165,18 @@ readonly class RDAPService 'GET', $rdapServerUrl.'domain/'.$idnDomain )->toArray(); } catch (\Throwable $e) { - if (null !== $domain) { - $this->logger->notice('The domain name {idnDomain} has been deleted from the WHOIS database.', [ - 'idnDomain' => $idnDomain, - ]); - - $domain->setDeleted(true) - ->updateTimestamps(); - $this->em->persist($domain); - $this->em->flush(); - } - if ($e instanceof ClientException && 404 === $e->getResponse()->getStatusCode()) { + if (null !== $domain) { + $this->logger->notice('The domain name {idnDomain} has been deleted from the WHOIS database.', [ + 'idnDomain' => $idnDomain, + ]); + + $domain->setDeleted(true) + ->updateTimestamps(); + $this->em->persist($domain); + $this->em->flush(); + } + throw new NotFoundHttpException('The domain name is not present in the WHOIS database.'); }