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
{
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);

View File

@@ -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", [

View File

@@ -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 */

View File

@@ -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();

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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);