diff --git a/src/Config/Connector/GandiConnector.php b/src/Config/Connector/GandiConnector.php index 469a5b2..1d715b1 100644 --- a/src/Config/Connector/GandiConnector.php +++ b/src/Config/Connector/GandiConnector.php @@ -5,6 +5,7 @@ namespace App\Config\Connector; use App\Entity\Domain; use Symfony\Component\HttpClient\HttpOptions; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -89,7 +90,6 @@ readonly class GandiConnector implements ConnectorInterface } /** - * @throws \Exception * @throws TransportExceptionInterface */ public static function verifyAuthData(array $authData, HttpClientInterface $client): array @@ -106,7 +106,7 @@ readonly class GandiConnector implements ConnectorInterface || true !== $ownerLegalAge || true !== $waiveRetractationPeriod ) { - throw new \Exception('Bad authData schema'); + throw new BadRequestHttpException('Bad authData schema'); } $response = $client->request('GET', '/v5/organization/user-info', (new HttpOptions()) @@ -117,7 +117,7 @@ readonly class GandiConnector implements ConnectorInterface ); if (Response::HTTP_OK !== $response->getStatusCode()) { - throw new \Exception('The status of these credentials is not valid'); + throw new BadRequestHttpException('The status of these credentials is not valid'); } $authDataReturned = [ diff --git a/src/Controller/ConnectorController.php b/src/Controller/ConnectorController.php index c7f22df..e6d641a 100644 --- a/src/Controller/ConnectorController.php +++ b/src/Controller/ConnectorController.php @@ -12,6 +12,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\Exception\TransportExceptionInterface; @@ -75,7 +76,7 @@ class ConnectorController extends AbstractController } elseif (ConnectorProvider::GANDI === $provider) { $authData = GandiConnector::verifyAuthData($connector->getAuthData(), $client); } else { - throw new \Exception('Unknown provider'); + throw new BadRequestHttpException('Unknown provider'); } $connector->setAuthData($authData);