Handle references ending in 404

Catch the exception and return null.
That is already a possible return type which should be handled by
callers.

Add test case with referenced 404 image.
This commit is contained in:
Daniel Siepmann 2021-08-31 09:34:01 +02:00
parent 73db8b5d9d
commit 592269baa8
3 changed files with 27 additions and 2 deletions

View file

@ -27,6 +27,7 @@ use WerkraumMedia\ThueCat\Domain\Import\EntityMapper\EntityRegistry;
use WerkraumMedia\ThueCat\Domain\Import\EntityMapper\JsonDecode;
use WerkraumMedia\ThueCat\Domain\Import\Entity\Properties\ForeignReference;
use WerkraumMedia\ThueCat\Domain\Import\Importer\FetchData;
use WerkraumMedia\ThueCat\Domain\Import\Importer\FetchData\InvalidResponseException;
/**
* Can be used to resolve foreign references.
@ -66,7 +67,12 @@ class ResolveForeignReference
ForeignReference $foreignReference,
string $language
): ?object {
$jsonLD = $this->fetchData->jsonLDFromUrl($foreignReference->getId());
try {
$jsonLD = $this->fetchData->jsonLDFromUrl($foreignReference->getId());
} catch (InvalidResponseException $e) {
return null;
}
$jsonEntity = $jsonLD['@graph'][0] ?? null;
if ($jsonEntity === null) {
return null;

View file

@ -0,0 +1,19 @@
HTTP/1.1 404 Not Found
Date: Wed, 17 Feb 2021 08:03:50 GMT
Content-Type: application/ld+json; charset=utf-8
Content-Length: 7366
Connection: keep-alive
Set-Cookie: ahSession=3e3e3f03b24a3a9f7eea750ec4c9b99774e2c09e;path=/;expires=Sat, 20 Mar 2021 08:03:50 GMT;httpOnly=true;
Access-Control-Allow-Methods: HEAD, GET, POST, DELETE, OPTIONS
Access-Control-Allow-Headers: Authorization, Content-Type
Strict-Transport-Security: max-age=15724800; includeSubDomains
Access-Control-Allow-Credentials: true
X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Feature-Policy: microphone 'none'; camera 'none'; payment 'none'
Content-Security-Policy: default-src 'self'; script-src 'self' 'sha256-xfTbtWk8kVI65iLJs8LB3lWf2g0g10DS71pDdoutFHc='; style-src 'self' 'unsafe-inline' https://stackpath.bootstrapcdn.com; img-src 'self' data: blob: *
Access-Control-Allow-Origin: https://cdb.thuecat.org
{"error":"404"}