feat: explcit HTTP errors

This commit is contained in:
Maël Gangloff
2024-08-06 21:43:37 +02:00
parent e46851ca54
commit 342b3ff987
4 changed files with 12 additions and 15 deletions

View File

@@ -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.', [

View File

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