Skip to content

Commit

Permalink
chore: Exception type
Browse files Browse the repository at this point in the history
  • Loading branch information
maelgangloff committed Aug 30, 2024
1 parent ceea587 commit 01a0f8e
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Config/Provider/GandiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Config/Provider/OvhProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -91,7 +91,7 @@ public function orderDomain(Domain $domain, bool $dryRun = false): void
);
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", [
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/ConnectorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function createConnector(Request $request, HttpClientInterface $client):
]);

if (null === $provider) {
throw new \Exception('Provider not found');
throw new BadRequestHttpException('Provider not found');
}

/** @var AbstractProvider $connectorProviderClass */
Expand Down
2 changes: 1 addition & 1 deletion src/MessageHandler/OrderDomainHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __invoke(OrderDomain $message): void
try {
$provider = $connector->getProvider();
if (null === $provider) {
throw new \Exception('Provider not found');
throw new \InvalidArgumentException('Provider not found');
}

$connectorProviderClass = $provider->getConnectorProvider();
Expand Down
5 changes: 4 additions & 1 deletion src/Notifier/DomainOrderErrorNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,8 @@ public function __construct(

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.")
Expand All @@ -41,7 +44,7 @@ public function asPushMessage(?RecipientInterface $recipient = null, ?string $tr
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)
Expand Down
2 changes: 1 addition & 1 deletion src/Notifier/DomainOrderNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function asPushMessage(?RecipientInterface $recipient = null, ?string $tr
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)
Expand Down
2 changes: 1 addition & 1 deletion src/Notifier/DomainUpdateErrorNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function asPushMessage(?RecipientInterface $recipient = null, ?string $tr
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)
Expand Down
2 changes: 1 addition & 1 deletion src/Notifier/DomainUpdateNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function asPushMessage(?RecipientInterface $recipient = null, ?string $tr
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)
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ChatNotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function sendChatNotification(WatchList $watchList, DomainWatchdogNotific
$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);
Expand Down

0 comments on commit 01a0f8e

Please sign in to comment.