From 01a0f8e688788b661f59f8225755aed30bc09dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Fri, 30 Aug 2024 12:54:42 +0200 Subject: [PATCH] chore: Exception type --- src/Config/Provider/GandiProvider.php | 4 ++-- src/Config/Provider/OvhProvider.php | 6 +++--- src/Controller/ConnectorController.php | 3 ++- src/MessageHandler/OrderDomainHandler.php | 2 +- src/Notifier/DomainOrderErrorNotification.php | 5 ++++- src/Notifier/DomainOrderNotification.php | 2 +- src/Notifier/DomainUpdateErrorNotification.php | 2 +- src/Notifier/DomainUpdateNotification.php | 2 +- src/Service/ChatNotificationService.php | 2 +- 9 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Config/Provider/GandiProvider.php b/src/Config/Provider/GandiProvider.php index 0c1226c..1bbb988 100644 --- a/src/Config/Provider/GandiProvider.php +++ b/src/Config/Provider/GandiProvider.php @@ -29,12 +29,12 @@ class GandiProvider extends AbstractProvider public function orderDomain(Domain $domain, bool $dryRun = false): void { if (!$domain->getDeleted()) { - throw new \Exception('The domain name still appears in the WHOIS database'); + throw new \InvalidArgumentException('The domain name still appears in the WHOIS database'); } $ldhName = $domain->getLdhName(); if (!$ldhName) { - throw new \Exception('Domain name cannot be null'); + throw new \InvalidArgumentException('Domain name cannot be null'); } $authData = self::verifyAuthData($this->authData, $this->client); diff --git a/src/Config/Provider/OvhProvider.php b/src/Config/Provider/OvhProvider.php index 01f3b3b..38f1138 100644 --- a/src/Config/Provider/OvhProvider.php +++ b/src/Config/Provider/OvhProvider.php @@ -49,12 +49,12 @@ class OvhProvider extends AbstractProvider public function orderDomain(Domain $domain, bool $dryRun = false): void { if (!$domain->getDeleted()) { - throw new \Exception('The domain name still appears in the WHOIS database'); + throw new \InvalidArgumentException('The domain name still appears in the WHOIS database'); } $ldhName = $domain->getLdhName(); if (!$ldhName) { - throw new \Exception('Domain name cannot be null'); + throw new \InvalidArgumentException('Domain name cannot be null'); } $authData = self::verifyAuthData($this->authData, $this->client); @@ -91,7 +91,7 @@ class OvhProvider extends AbstractProvider ); if (empty($offer)) { $conn->delete("/order/cart/{$cartId}"); - throw new \Exception('Cannot buy this domain name'); + throw new \InvalidArgumentException('Cannot buy this domain name'); } $item = $conn->post("/order/cart/{$cartId}/domain", [ diff --git a/src/Controller/ConnectorController.php b/src/Controller/ConnectorController.php index f560b08..df91dd5 100644 --- a/src/Controller/ConnectorController.php +++ b/src/Controller/ConnectorController.php @@ -10,6 +10,7 @@ use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -67,7 +68,7 @@ class ConnectorController extends AbstractController ]); if (null === $provider) { - throw new \Exception('Provider not found'); + throw new BadRequestHttpException('Provider not found'); } /** @var AbstractProvider $connectorProviderClass */ diff --git a/src/MessageHandler/OrderDomainHandler.php b/src/MessageHandler/OrderDomainHandler.php index 3709115..7dc028d 100644 --- a/src/MessageHandler/OrderDomainHandler.php +++ b/src/MessageHandler/OrderDomainHandler.php @@ -66,7 +66,7 @@ final readonly class OrderDomainHandler try { $provider = $connector->getProvider(); if (null === $provider) { - throw new \Exception('Provider not found'); + throw new \InvalidArgumentException('Provider not found'); } $connectorProviderClass = $provider->getConnectorProvider(); diff --git a/src/Notifier/DomainOrderErrorNotification.php b/src/Notifier/DomainOrderErrorNotification.php index 397e380..b86694c 100644 --- a/src/Notifier/DomainOrderErrorNotification.php +++ b/src/Notifier/DomainOrderErrorNotification.php @@ -2,6 +2,7 @@ namespace App\Notifier; +use App\Config\WebhookScheme; use App\Entity\Domain; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Component\Mime\Address; @@ -23,6 +24,8 @@ class DomainOrderErrorNotification extends DomainWatchdogNotification public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage { + $webhookScheme = WebhookScheme::from($transport); + $ldhName = $this->domain->getLdhName(); $this->subject("Error: Domain Order $ldhName") ->content("Domain name $ldhName tried to be purchased. The attempt failed.") @@ -41,7 +44,7 @@ class DomainOrderErrorNotification extends DomainWatchdogNotification return PushMessage::fromNotification($this); } - public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): EmailMessage + public function asEmailMessage(EmailRecipientInterface $recipient): EmailMessage { return new EmailMessage((new TemplatedEmail()) ->from($this->sender) diff --git a/src/Notifier/DomainOrderNotification.php b/src/Notifier/DomainOrderNotification.php index 3d99d9f..0c17497 100644 --- a/src/Notifier/DomainOrderNotification.php +++ b/src/Notifier/DomainOrderNotification.php @@ -46,7 +46,7 @@ class DomainOrderNotification extends DomainWatchdogNotification return PushMessage::fromNotification($this); } - public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): EmailMessage + public function asEmailMessage(EmailRecipientInterface $recipient): EmailMessage { return new EmailMessage((new TemplatedEmail()) ->from($this->sender) diff --git a/src/Notifier/DomainUpdateErrorNotification.php b/src/Notifier/DomainUpdateErrorNotification.php index 868a7db..6b2e1e5 100644 --- a/src/Notifier/DomainUpdateErrorNotification.php +++ b/src/Notifier/DomainUpdateErrorNotification.php @@ -41,7 +41,7 @@ class DomainUpdateErrorNotification extends DomainWatchdogNotification return PushMessage::fromNotification($this); } - public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): EmailMessage + public function asEmailMessage(EmailRecipientInterface $recipient): EmailMessage { return new EmailMessage((new TemplatedEmail()) ->from($this->sender) diff --git a/src/Notifier/DomainUpdateNotification.php b/src/Notifier/DomainUpdateNotification.php index 3ea3c6c..65c02cd 100644 --- a/src/Notifier/DomainUpdateNotification.php +++ b/src/Notifier/DomainUpdateNotification.php @@ -44,7 +44,7 @@ class DomainUpdateNotification extends DomainWatchdogNotification return PushMessage::fromNotification($this); } - public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): EmailMessage + public function asEmailMessage(EmailRecipientInterface $recipient): EmailMessage { return new EmailMessage((new TemplatedEmail()) ->from($this->sender) diff --git a/src/Service/ChatNotificationService.php b/src/Service/ChatNotificationService.php index 19aef7b..8e73f00 100644 --- a/src/Service/ChatNotificationService.php +++ b/src/Service/ChatNotificationService.php @@ -42,7 +42,7 @@ readonly class ChatNotificationService $transportFactory = new $transportFactoryClass(); $push = $notification->asPushMessage(new NoRecipient()); - $chat = $notification->asChatMessage(new NoRecipient()); + $chat = $notification->asChatMessage(new NoRecipient(), $webhookScheme->value); try { $factory = $transportFactory->create($dsn);