feat: explcit HTTP errors

This commit is contained in:
Maël Gangloff 2024-08-06 21:52:35 +02:00
parent 21298b07a2
commit e393bcf0af
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
2 changed files with 5 additions and 4 deletions

View File

@ -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 = [

View File

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