mirror of
https://github.com/friendica/friendica
synced 2025-01-11 04:44:43 +00:00
Catch all errors thrown by "fetchRaw"
This commit is contained in:
parent
6870ccc00e
commit
2b513a48c7
8 changed files with 64 additions and 28 deletions
|
@ -73,7 +73,12 @@ class Avatar
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
|
try {
|
||||||
|
$fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Logger::notice('Avatar is invalid', ['avatar' => $avatar, 'error' => $th]);
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
$img_str = $fetchResult->getBody();
|
$img_str = $fetchResult->getBody();
|
||||||
if (empty($img_str)) {
|
if (empty($img_str)) {
|
||||||
|
|
|
@ -57,6 +57,7 @@ class ExternalResource implements ICanReadFromStorage
|
||||||
try {
|
try {
|
||||||
$fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
|
$fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
|
Logger::notice('URL is invalid', ['url' => $data->url, 'error' => $exception]);
|
||||||
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
|
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
|
||||||
}
|
}
|
||||||
if (!empty($fetchResult) && $fetchResult->isSuccess()) {
|
if (!empty($fetchResult) && $fetchResult->isSuccess()) {
|
||||||
|
|
|
@ -189,17 +189,22 @@ class APContact
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$local_owner = [];
|
$local_owner = [];
|
||||||
|
|
||||||
$curlResult = HTTPSignature::fetchRaw($url);
|
try {
|
||||||
$failed = empty($curlResult) || empty($curlResult->getBody()) ||
|
$curlResult = HTTPSignature::fetchRaw($url);
|
||||||
(!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
|
$failed = empty($curlResult) || empty($curlResult->getBody()) ||
|
||||||
|
(!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
|
||||||
|
|
||||||
if (!$failed) {
|
if (!$failed) {
|
||||||
$data = json_decode($curlResult->getBody(), true);
|
$data = json_decode($curlResult->getBody(), true);
|
||||||
$failed = empty($data) || !is_array($data);
|
$failed = empty($data) || !is_array($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$failed && ($curlResult->getReturnCode() == 410)) {
|
if (!$failed && ($curlResult->getReturnCode() == 410)) {
|
||||||
$data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
|
$data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
|
||||||
|
}
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Logger::notice('Error fetching url', ['url' => $url, 'error' => $th]);
|
||||||
|
$failed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($failed) {
|
if ($failed) {
|
||||||
|
|
|
@ -2216,16 +2216,21 @@ class Contact
|
||||||
if (($contact['avatar'] != $avatar) || empty($contact['blurhash'])) {
|
if (($contact['avatar'] != $avatar) || empty($contact['blurhash'])) {
|
||||||
$update_fields = ['avatar' => $avatar];
|
$update_fields = ['avatar' => $avatar];
|
||||||
if (!Network::isLocalLink($avatar)) {
|
if (!Network::isLocalLink($avatar)) {
|
||||||
$fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
|
try {
|
||||||
|
$fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
|
||||||
|
|
||||||
$img_str = $fetchResult->getBody();
|
$img_str = $fetchResult->getBody();
|
||||||
if (!empty($img_str)) {
|
if (!empty($img_str)) {
|
||||||
$image = new Image($img_str, Images::getMimeTypeByData($img_str));
|
$image = new Image($img_str, Images::getMimeTypeByData($img_str));
|
||||||
if ($image->isValid()) {
|
if ($image->isValid()) {
|
||||||
$update_fields['blurhash'] = $image->getBlurHash();
|
$update_fields['blurhash'] = $image->getBlurHash();
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Logger::notice('Error fetching avatar', ['avatar' => $avatar, 'error' => $th]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} elseif (!empty($contact['blurhash'])) {
|
} elseif (!empty($contact['blurhash'])) {
|
||||||
$update_fields['blurhash'] = null;
|
$update_fields['blurhash'] = null;
|
||||||
|
|
|
@ -125,8 +125,13 @@ class Link
|
||||||
{
|
{
|
||||||
$timeout = DI::config()->get('system', 'xrd_timeout');
|
$timeout = DI::config()->get('system', 'xrd_timeout');
|
||||||
|
|
||||||
$curlResult = HTTPSignature::fetchRaw($url, 0, [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => $accept]);
|
try {
|
||||||
if (empty($curlResult) || !$curlResult->isSuccess()) {
|
$curlResult = HTTPSignature::fetchRaw($url, 0, [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => $accept]);
|
||||||
|
if (empty($curlResult) || !$curlResult->isSuccess()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Logger::notice('Error fetching url', ['url' => $url, 'error' => $th]);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$fields = ['mimetype' => $curlResult->getHeader('Content-Type')[0]];
|
$fields = ['mimetype' => $curlResult->getHeader('Content-Type')[0]];
|
||||||
|
|
|
@ -83,13 +83,18 @@ class Proxy extends BaseModule
|
||||||
$request['url'] = str_replace(' ', '+', $request['url']);
|
$request['url'] = str_replace(' ', '+', $request['url']);
|
||||||
|
|
||||||
// Fetch the content with the local user
|
// Fetch the content with the local user
|
||||||
$fetchResult = HTTPSignature::fetchRaw($request['url'], DI::userSession()->getLocalUserId(), [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE], 'timeout' => 10]);
|
try {
|
||||||
$img_str = $fetchResult->getBody();
|
$fetchResult = HTTPSignature::fetchRaw($request['url'], DI::userSession()->getLocalUserId(), [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE], 'timeout' => 10]);
|
||||||
|
$img_str = $fetchResult->getBody();
|
||||||
|
|
||||||
if (!$fetchResult->isSuccess() || empty($img_str)) {
|
if (!$fetchResult->isSuccess() || empty($img_str)) {
|
||||||
Logger::notice('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]);
|
Logger::notice('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]);
|
||||||
|
self::responseError();
|
||||||
|
// stop.
|
||||||
|
}
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Logger::notice('Error fetching image', ['image' => $request['url'], 'error' => $th]);
|
||||||
self::responseError();
|
self::responseError();
|
||||||
// stop.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => DI::userSession()->getLocalUserId(), 'image' => $request['url']]);
|
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => DI::userSession()->getLocalUserId(), 'image' => $request['url']]);
|
||||||
|
|
|
@ -570,7 +570,12 @@ class Processor
|
||||||
*/
|
*/
|
||||||
public static function isActivityGone(string $url): bool
|
public static function isActivityGone(string $url): bool
|
||||||
{
|
{
|
||||||
$curlResult = HTTPSignature::fetchRaw($url, 0);
|
try {
|
||||||
|
$curlResult = HTTPSignature::fetchRaw($url, 0);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Logger::notice('Error fetching url', ['url' => $url, 'error' => $th]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (Network::isUrlBlocked($url)) {
|
if (Network::isUrlBlocked($url)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -422,7 +422,12 @@ class HTTPSignature
|
||||||
*/
|
*/
|
||||||
public static function fetch(string $request, int $uid): array
|
public static function fetch(string $request, int $uid): array
|
||||||
{
|
{
|
||||||
$curlResult = self::fetchRaw($request, $uid);
|
try {
|
||||||
|
$curlResult = self::fetchRaw($request, $uid);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Logger::notice('Error fetching url', ['url' => $request, 'error' => $th]);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($curlResult)) {
|
if (empty($curlResult)) {
|
||||||
return [];
|
return [];
|
||||||
|
|
Loading…
Reference in a new issue