Exception handling added at many places

This commit is contained in:
Michael 2024-08-25 18:35:24 +00:00
parent e6daaf49ce
commit 518382036b
16 changed files with 174 additions and 44 deletions

View file

@ -1411,12 +1411,18 @@ class User
$photo_failure = false;
$filename = basename($photo);
$curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
if ($curlResult->isSuccess()) {
Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
$img_str = $curlResult->getBodyString();
$type = $curlResult->getContentType();
} else {
try {
$curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
if ($curlResult->isSuccess()) {
Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
$img_str = $curlResult->getBodyString();
$type = $curlResult->getContentType();
} else {
$img_str = '';
$type = '';
}
} catch (\Throwable $th) {
Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
$img_str = '';
$type = '';
}