[ENTITY][Link] Sometimes URLs don't work, handle that

This commit is contained in:
Diogo Peralta Cordeiro 2021-08-14 15:39:55 +01:00
parent d23312aff9
commit 2e3ab5bdfb
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
1 changed files with 6 additions and 1 deletions

View File

@ -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 {