From 060a5abef14999692facb25d6d1e614938126972 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Sat, 14 Aug 2021 15:39:55 +0100 Subject: [PATCH] [ENTITY][Link] Sometimes URLs don't work, handle that --- src/Entity/Link.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Entity/Link.php b/src/Entity/Link.php index 30f749cce6..38f1a27081 100644 --- a/src/Entity/Link.php +++ b/src/Entity/Link.php @@ -29,6 +29,7 @@ use App\Util\Exception\DuplicateFoundException; use App\Util\Exception\NotFoundException; use DateTimeInterface; use InvalidArgumentException; +use Symfony\Component\HttpClient\Exception\ClientException; /** * Entity for representing a Link @@ -138,7 +139,11 @@ class Link extends Entity if (Common::isValidHttpUrl($url)) { $head = HTTPClient::head($url); // This must come before getInfo given that Symfony HTTPClient is lazy (thus forcing curl exec) - $headers = $head->getHeaders(); + try { + $headers = $head->getHeaders(); + } catch (ClientException $e) { + throw new InvalidArgumentException(previous: $e); + } $url = $head->getInfo('url'); // The last effective url (after getHeaders, so it follows redirects) $url_hash = hash(self::URLHASH_ALGO, $url); try {