Skip to content

Commit

Permalink
Catch exception
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Feb 18, 2024
1 parent f2a2ba2 commit 51e4f4e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Service/ImageFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateInterval;
use Psr\Cache\CacheItemPoolInterface;
use SapientPro\ImageComparator\ImageComparator;
use Symfony\Component\ErrorHandler\Error\FatalError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -32,8 +33,12 @@ public function getImageHash(string $url): ?string
} else {
$contentType = $response->getHeaders(false)['content-type'][0] ?? '';
if (str_starts_with($contentType, 'image/')) {
$image = @imagecreatefromstring($response->getContent());
error_clear_last();
try {
$image = @imagecreatefromstring($response->getContent());
} catch (FatalError) {
// ignore that stupidity
$image = false;
}
if ($image !== false) {
$cacheItem->set(
$this->imageComparator->convertHashToBinaryString(
Expand Down

0 comments on commit 51e4f4e

Please sign in to comment.