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();
if (empty($img_str)) {
try {
$fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
} 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);
}
if (!empty($fetchResult) && $fetchResult->isSuccess()) {
if (empty($data)) {
$local_owner = [];
- $curlResult = HTTPSignature::fetchRaw($url);
- $failed = empty($curlResult) || empty($curlResult->getBody()) ||
- (!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
-
- if (!$failed) {
- $data = json_decode($curlResult->getBody(), true);
- $failed = empty($data) || !is_array($data);
- }
+ try {
+ $curlResult = HTTPSignature::fetchRaw($url);
+ $failed = empty($curlResult) || empty($curlResult->getBody()) ||
+ (!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
+
+ if (!$failed) {
+ $data = json_decode($curlResult->getBody(), true);
+ $failed = empty($data) || !is_array($data);
+ }
- if (!$failed && ($curlResult->getReturnCode() == 410)) {
- $data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
+ if (!$failed && ($curlResult->getReturnCode() == 410)) {
+ $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 (($contact['avatar'] != $avatar) || empty($contact['blurhash'])) {
$update_fields = ['avatar' => $avatar];
if (!Network::isLocalLink($avatar)) {
- $fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
-
- $img_str = $fetchResult->getBody();
- if (!empty($img_str)) {
- $image = new Image($img_str, Images::getMimeTypeByData($img_str));
- if ($image->isValid()) {
- $update_fields['blurhash'] = $image->getBlurHash();
- } else {
- return;
+ try {
+ $fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
+
+ $img_str = $fetchResult->getBody();
+ if (!empty($img_str)) {
+ $image = new Image($img_str, Images::getMimeTypeByData($img_str));
+ if ($image->isValid()) {
+ $update_fields['blurhash'] = $image->getBlurHash();
+ } else {
+ return;
+ }
}
+ } catch (\Throwable $th) {
+ Logger::notice('Error fetching avatar', ['avatar' => $avatar, 'error' => $th]);
+ return;
}
} elseif (!empty($contact['blurhash'])) {
$update_fields['blurhash'] = null;
{
$timeout = DI::config()->get('system', 'xrd_timeout');
- $curlResult = HTTPSignature::fetchRaw($url, 0, [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => $accept]);
- if (empty($curlResult) || !$curlResult->isSuccess()) {
+ try {
+ $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 [];
}
$fields = ['mimetype' => $curlResult->getHeader('Content-Type')[0]];
$request['url'] = str_replace(' ', '+', $request['url']);
// Fetch the content with the local user
- $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)) {
- Logger::notice('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]);
+ try {
+ $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)) {
+ 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();
- // stop.
}
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => DI::userSession()->getLocalUserId(), 'image' => $request['url']]);
*/
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)) {
return true;
*/
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)) {
return [];