chore: Exception type

This commit is contained in:
Maël Gangloff
2024-08-30 12:54:42 +02:00
parent ceea587585
commit 01a0f8e688
9 changed files with 16 additions and 12 deletions

View File

@@ -29,12 +29,12 @@ class GandiProvider extends AbstractProvider
public function orderDomain(Domain $domain, bool $dryRun = false): void public function orderDomain(Domain $domain, bool $dryRun = false): void
{ {
if (!$domain->getDeleted()) { 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(); $ldhName = $domain->getLdhName();
if (!$ldhName) { 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); $authData = self::verifyAuthData($this->authData, $this->client);

View File

@@ -49,12 +49,12 @@ class OvhProvider extends AbstractProvider
public function orderDomain(Domain $domain, bool $dryRun = false): void public function orderDomain(Domain $domain, bool $dryRun = false): void
{ {
if (!$domain->getDeleted()) { 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(); $ldhName = $domain->getLdhName();
if (!$ldhName) { 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); $authData = self::verifyAuthData($this->authData, $this->client);
@@ -91,7 +91,7 @@ class OvhProvider extends AbstractProvider
); );
if (empty($offer)) { if (empty($offer)) {
$conn->delete("/order/cart/{$cartId}"); $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", [ $item = $conn->post("/order/cart/{$cartId}/domain", [

View File

@@ -10,6 +10,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -67,7 +68,7 @@ class ConnectorController extends AbstractController
]); ]);
if (null === $provider) { if (null === $provider) {
throw new \Exception('Provider not found'); throw new BadRequestHttpException('Provider not found');
} }
/** @var AbstractProvider $connectorProviderClass */ /** @var AbstractProvider $connectorProviderClass */

View File

@@ -66,7 +66,7 @@ final readonly class OrderDomainHandler
try { try {
$provider = $connector->getProvider(); $provider = $connector->getProvider();
if (null === $provider) { if (null === $provider) {
throw new \Exception('Provider not found'); throw new \InvalidArgumentException('Provider not found');
} }
$connectorProviderClass = $provider->getConnectorProvider(); $connectorProviderClass = $provider->getConnectorProvider();

View File

@@ -2,6 +2,7 @@
namespace App\Notifier; namespace App\Notifier;
use App\Config\WebhookScheme;
use App\Entity\Domain; use App\Entity\Domain;
use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Address;
@@ -23,6 +24,8 @@ class DomainOrderErrorNotification extends DomainWatchdogNotification
public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ?ChatMessage
{ {
$webhookScheme = WebhookScheme::from($transport);
$ldhName = $this->domain->getLdhName(); $ldhName = $this->domain->getLdhName();
$this->subject("Error: Domain Order $ldhName") $this->subject("Error: Domain Order $ldhName")
->content("Domain name $ldhName tried to be purchased. The attempt failed.") ->content("Domain name $ldhName tried to be purchased. The attempt failed.")
@@ -41,7 +44,7 @@ class DomainOrderErrorNotification extends DomainWatchdogNotification
return PushMessage::fromNotification($this); return PushMessage::fromNotification($this);
} }
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): EmailMessage public function asEmailMessage(EmailRecipientInterface $recipient): EmailMessage
{ {
return new EmailMessage((new TemplatedEmail()) return new EmailMessage((new TemplatedEmail())
->from($this->sender) ->from($this->sender)

View File

@@ -46,7 +46,7 @@ class DomainOrderNotification extends DomainWatchdogNotification
return PushMessage::fromNotification($this); return PushMessage::fromNotification($this);
} }
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): EmailMessage public function asEmailMessage(EmailRecipientInterface $recipient): EmailMessage
{ {
return new EmailMessage((new TemplatedEmail()) return new EmailMessage((new TemplatedEmail())
->from($this->sender) ->from($this->sender)

View File

@@ -41,7 +41,7 @@ class DomainUpdateErrorNotification extends DomainWatchdogNotification
return PushMessage::fromNotification($this); return PushMessage::fromNotification($this);
} }
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): EmailMessage public function asEmailMessage(EmailRecipientInterface $recipient): EmailMessage
{ {
return new EmailMessage((new TemplatedEmail()) return new EmailMessage((new TemplatedEmail())
->from($this->sender) ->from($this->sender)

View File

@@ -44,7 +44,7 @@ class DomainUpdateNotification extends DomainWatchdogNotification
return PushMessage::fromNotification($this); return PushMessage::fromNotification($this);
} }
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): EmailMessage public function asEmailMessage(EmailRecipientInterface $recipient): EmailMessage
{ {
return new EmailMessage((new TemplatedEmail()) return new EmailMessage((new TemplatedEmail())
->from($this->sender) ->from($this->sender)

View File

@@ -42,7 +42,7 @@ readonly class ChatNotificationService
$transportFactory = new $transportFactoryClass(); $transportFactory = new $transportFactoryClass();
$push = $notification->asPushMessage(new NoRecipient()); $push = $notification->asPushMessage(new NoRecipient());
$chat = $notification->asChatMessage(new NoRecipient()); $chat = $notification->asChatMessage(new NoRecipient(), $webhookScheme->value);
try { try {
$factory = $transportFactory->create($dsn); $factory = $transportFactory->create($dsn);