feat: forward the error message to the client if an error occurs on the RDAP server side

This commit is contained in:
Maël Gangloff
2025-11-12 19:43:36 +01:00
parent aebc90d34b
commit 88a3954c6e
3 changed files with 22 additions and 2 deletions

View File

@@ -42,6 +42,7 @@ api_platform:
App\Exception\TldNotSupportedException: 400
App\Exception\UnknownRdapServerException: 400
App\Exception\UnsupportedDsnScheme: 400
App\Exception\RdapServerException: 400
# Provider exception
App\Exception\Provider\UserNoExplicitConsentException: 451

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Exception;
use Symfony\Component\HttpClient\Exception\ServerException;
class RdapServerException extends \Exception
{
public static function fromServerException(ServerException $e): self
{
return new self($e->getMessage(), $e->getCode(), $e);
}
}

View File

@@ -18,6 +18,7 @@ use App\Entity\RdapServer;
use App\Entity\Tld;
use App\Exception\DomainNotFoundException;
use App\Exception\MalformedDomainException;
use App\Exception\RdapServerException;
use App\Exception\TldNotSupportedException;
use App\Exception\UnknownRdapServerException;
use App\Repository\DomainEntityRepository;
@@ -37,6 +38,7 @@ use Doctrine\ORM\OptimisticLockException;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpClient\Exception\ClientException;
use Symfony\Component\HttpClient\Exception\ServerException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
@@ -249,7 +251,7 @@ class RDAPService
]);
try {
$req = $this->client->request('GET', $rdapServerUrl.'domain/'.$idnDomain);
$req = $this->client->request('GET', 'http://localhost:3000');
$this->statService->incrementStat('stats.rdap_queries.count');
return $req->toArray();
@@ -292,13 +294,17 @@ class RDAPService
$this->em->flush();
}
throw DomainNotFoundException::fromDomain($idnDomain);
return DomainNotFoundException::fromDomain($idnDomain);
}
$this->logger->error('Unable to perform an RDAP query for this domain name', [
'ldhName' => $idnDomain,
]);
if ($e instanceof ServerException) {
return RdapServerException::fromServerException($e);
}
return $e;
}