fix: [UI] Catch exception when custom file is not readable

pull/9588/head
Jakub Onderka 2024-02-23 10:01:18 +01:00 committed by Sami Mokaddem
parent f09fdad92d
commit c07ee0066c
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 9 additions and 2 deletions

View File

@ -27,8 +27,15 @@ class ImageHelper extends AppHelper
throw new InvalidArgumentException("Only SVG and PNG images are supported");
}
$fileContent = base64_encode(FileAccessTool::readFromFile($imagePath));
$base64 = "data:$mime;base64,$fileContent";
try {
$fileContent = FileAccessTool::readFromFile($imagePath);
} catch (Exception $e) {
CakeLog::warning($e);
return 'data:null'; // in case file doesn't exists or is not readable
}
$fileContentEncoded = base64_encode($fileContent);
$base64 = "data:$mime;base64,$fileContentEncoded";
return $this->imageCache[$imagePath] = $base64;
}