mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: explcit HTTP errors
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Config\Connector;
|
||||
|
||||
use App\Entity\Domain;
|
||||
use Ovh\Api;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
readonly class OvhConnector implements ConnectorInterface
|
||||
{
|
||||
@@ -141,7 +142,7 @@ readonly class OvhConnector implements ConnectorInterface
|
||||
|| true !== $ownerLegalAge
|
||||
|| true !== $waiveRetractationPeriod
|
||||
) {
|
||||
throw new \Exception('Bad authData schema');
|
||||
throw new BadRequestHttpException('Bad authData schema');
|
||||
}
|
||||
|
||||
$conn = new Api(
|
||||
@@ -174,7 +175,7 @@ readonly class OvhConnector implements ConnectorInterface
|
||||
}
|
||||
|
||||
if (!$ok) {
|
||||
throw new \Exception('The credentials provided do not have enough permissions to purchase a domain name.');
|
||||
throw new BadRequestHttpException('The credentials provided do not have enough permissions to purchase a domain name.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,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;
|
||||
|
||||
@@ -74,7 +75,7 @@ class ConnectorController extends AbstractController
|
||||
'username' => $user->getUserIdentifier(),
|
||||
]);
|
||||
} else {
|
||||
throw new \Exception('Unknown provider');
|
||||
throw new BadRequestHttpException('Unknown provider');
|
||||
}
|
||||
|
||||
$this->logger->info('The new API connector requested by {username} has been successfully registered.', [
|
||||
|
||||
@@ -10,7 +10,6 @@ use App\Service\RDAPService;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Random\Randomizer;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
||||
@@ -35,6 +34,7 @@ class DomainRefreshController extends AbstractController
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ExceptionInterface
|
||||
* @throws \Exception
|
||||
* @throws HttpExceptionInterface
|
||||
*/
|
||||
public function __invoke(string $ldhName, KernelInterface $kernel): ?Domain
|
||||
{
|
||||
@@ -72,11 +72,7 @@ class DomainRefreshController extends AbstractController
|
||||
}
|
||||
|
||||
$updatedAt = null === $domain ? new \DateTimeImmutable('now') : $domain->getUpdatedAt();
|
||||
try {
|
||||
$domain = $this->RDAPService->registerDomain($idnDomain);
|
||||
} catch (HttpExceptionInterface) {
|
||||
throw new NotFoundHttpException('This domain name cannot be found in the WHOIS database');
|
||||
}
|
||||
$domain = $this->RDAPService->registerDomain($idnDomain);
|
||||
|
||||
$randomizer = new Randomizer();
|
||||
$watchLists = $randomizer->shuffleArray($domain->getWatchLists()->toArray());
|
||||
|
||||
@@ -25,6 +25,8 @@ use App\Repository\TldRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Exception\ORMException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||
@@ -122,10 +124,10 @@ readonly class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws HttpExceptionInterface
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function registerDomain(string $fqdn): Domain
|
||||
{
|
||||
@@ -141,7 +143,7 @@ readonly class RDAPService
|
||||
$rdapServer = $this->rdapServerRepository->findOneBy(['tld' => $tld], ['updatedAt' => 'DESC']);
|
||||
|
||||
if (null === $rdapServer) {
|
||||
throw new \Exception('Unable to determine which RDAP server to contact');
|
||||
throw new NotFoundHttpException('Unable to determine which RDAP server to contact');
|
||||
}
|
||||
|
||||
/** @var ?Domain $domain */
|
||||
@@ -331,14 +333,11 @@ readonly class RDAPService
|
||||
return $domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getTld($domain): ?object
|
||||
{
|
||||
$lastDotPosition = strrpos($domain, '.');
|
||||
if (false === $lastDotPosition) {
|
||||
throw new \Exception('Domain must contain at least one dot');
|
||||
throw new BadRequestException('Domain must contain at least one dot');
|
||||
}
|
||||
$tld = strtolower(substr($domain, $lastDotPosition + 1));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user