From 88a3954c6e9e08ad0e5c1ef523339dd7e3a8fc06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Wed, 12 Nov 2025 19:43:36 +0100 Subject: [PATCH] feat: forward the error message to the client if an error occurs on the RDAP server side --- config/packages/api_platform.yaml | 1 + src/Exception/RdapServerException.php | 13 +++++++++++++ src/Service/RDAPService.php | 10 ++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/Exception/RdapServerException.php diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index 63a8109..376274c 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -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 diff --git a/src/Exception/RdapServerException.php b/src/Exception/RdapServerException.php new file mode 100644 index 0000000..e4859a8 --- /dev/null +++ b/src/Exception/RdapServerException.php @@ -0,0 +1,13 @@ +getMessage(), $e->getCode(), $e); + } +} diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index 45ad315..6a1a261 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -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; }