Properly handle guzzle exception for fetching images

This commit is contained in:
Daniel Siepmann 2022-12-21 12:16:20 +00:00
parent fcbda4c093
commit 6570ec5ca9
2 changed files with 42 additions and 2 deletions

View file

@ -2,6 +2,7 @@
namespace Wrm\Events\Service;
use Exception;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\DataHandling\SlugHelper;
@ -177,7 +178,7 @@ class DestinationDataImportService
try {
$data = $this->dataFetcher->fetchSearchResult($import);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->error('Could not receive data.');
return 1;
}
@ -539,7 +540,13 @@ class DestinationDataImportService
$file = new \SplFileInfo($fileUrl);
$temporaryFilename = GeneralUtility::tempnam($file->getBasename());
$response = $this->dataFetcher->fetchImage($fileUrl);
try {
$response = $this->dataFetcher->fetchImage($fileUrl);
} catch (Exception $e) {
$this->logger->error('Cannot load file ' . $fileUrl);
return '';
}
$fileContent = $response->getBody()->__toString();
if ($response->getStatusCode() !== 200) {
$this->logger->error('Cannot load file ' . $fileUrl);

View file

@ -0,0 +1,33 @@
3.0.1
=====
Breaking
--------
Nothing
Features
--------
Nothing
Fixes
-----
* Do not break import on missing image
Guzzle might throw exceptions instead of returning the response.
We extend our import to also watch out for exceptions and handle them the same way
as a response other than 200.
Relates: #10253
Tasks
-----
Nothing
Deprecation
-----------
Nothing