Skip to content

Commit

Permalink
Handle errors gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Feb 18, 2024
1 parent d9ec609 commit b404bb0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Service/ImageFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@ public function getImageHash(string $url): ?string
$cacheItem->set(null);
} else {
$contentType = $response->getHeaders(false)['content-type'][0] ?? '';
if (!str_starts_with($contentType, 'image/')) {
$cacheItem->set(null);
} else {
$cacheItem->set(
$this->imageComparator->convertHashToBinaryString(
$this->imageComparator->hashImage(
imagecreatefromstring($response->getContent()),
if (str_starts_with($contentType, 'image/')) {
$image = @imagecreatefromstring($response->getContent());
if ($image !== false) {
$cacheItem->set(
$this->imageComparator->convertHashToBinaryString(
$this->imageComparator->hashImage(
$image,
),
),
),
);
);
}
}
}

if (!$cacheItem->get()) {
$cacheItem->set(null);
}
$cacheItem->expiresAfter(new DateInterval('P7D'));
$this->cache->save($cacheItem);

Expand Down

0 comments on commit b404bb0

Please sign in to comment.