feat: improve Connector abstract

This commit is contained in:
Maël Gangloff
2024-08-07 01:10:56 +02:00
parent e04e880d33
commit f3650f3b9f
6 changed files with 42 additions and 45 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Config\Connector;
use App\Entity\Domain;
use http\Exception\InvalidArgumentException;
use Symfony\Component\HttpClient\HttpOptions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@@ -29,26 +30,16 @@ readonly class GandiConnector implements ConnectorInterface
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);
$acceptConditions = $authData['acceptConditions'];
$ownerLegalAge = $authData['ownerLegalAge'];
$waiveRetractationPeriod = $authData['waiveRetractationPeriod'];
if (true !== $acceptConditions
|| true !== $ownerLegalAge
|| true !== $waiveRetractationPeriod) {
throw new HttpException(451, 'The user has not given explicit consent');
}
$user = $this->client->request('GET', '/v5/organization/user-info', (new HttpOptions())
->setAuthBearer($authData['token'])
->setHeader('Accept', 'application/json')
@@ -112,7 +103,7 @@ readonly class GandiConnector implements ConnectorInterface
if (true !== $acceptConditions
|| true !== $ownerLegalAge
|| true !== $waiveRetractationPeriod) {
throw new HttpException(451, 'The user has not given explicit consent', null);
throw new HttpException(451, 'The user has not given explicit consent');
}
$response = $client->request('GET', '/v5/organization/user-info', (new HttpOptions())