mirror of
https://github.com/friendica/friendica
synced 2025-04-19 09:50:11 +00:00
Merge pull request #12843 from annando/fetchraw-attachments
Catch all errors thrown by "fetchRaw"
This commit is contained in:
commit
a40ecb3902
22 changed files with 104 additions and 60 deletions
|
@ -120,8 +120,8 @@ class Statuses extends BaseApi
|
|||
self::setBoundaries($item['uri-id']);
|
||||
try {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
|
||||
} catch (\Exception $exception) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'exception' => $exception]);
|
||||
}
|
||||
}
|
||||
DBA::close($items);
|
||||
|
|
|
@ -77,8 +77,8 @@ class Bookmarks extends BaseApi
|
|||
self::setBoundaries($item['uri-id']);
|
||||
try {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
|
||||
} catch (\Exception $exception) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'exception' => $exception]);
|
||||
}
|
||||
}
|
||||
DBA::close($items);
|
||||
|
|
|
@ -79,8 +79,8 @@ class Favourited extends BaseApi
|
|||
self::setBoundaries($item['thr-parent-id']);
|
||||
try {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['thr-parent-id'], $uid, $display_quotes);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['thr-parent-id'], 'uid' => $uid, 'error' => $th]);
|
||||
} catch (\Exception $exception) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['thr-parent-id'], 'uid' => $uid, 'exception' => $exception]);
|
||||
}
|
||||
}
|
||||
DBA::close($items);
|
||||
|
|
|
@ -117,7 +117,7 @@ class Accounts extends BaseApi
|
|||
self::setBoundaries($member['contact-id']);
|
||||
try {
|
||||
$accounts[] = DI::mstdnAccount()->createFromContactId($member['contact-id'], $uid);
|
||||
} catch (\Throwable $th) {
|
||||
} catch (\Exception $exception) {
|
||||
}
|
||||
}
|
||||
DBA::close($members);
|
||||
|
|
|
@ -183,8 +183,8 @@ class Search extends BaseApi
|
|||
self::setBoundaries($item['uri-id']);
|
||||
try {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
|
||||
} catch (\Exception $exception) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'exception' => $exception]);
|
||||
}
|
||||
}
|
||||
DBA::close($items);
|
||||
|
|
|
@ -99,8 +99,8 @@ class Home extends BaseApi
|
|||
self::setBoundaries($item['uri-id']);
|
||||
try {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
|
||||
} catch (\Exception $exception) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'exception' => $exception]);
|
||||
}
|
||||
}
|
||||
DBA::close($items);
|
||||
|
|
|
@ -104,8 +104,8 @@ class ListTimeline extends BaseApi
|
|||
self::setBoundaries($item['uri-id']);
|
||||
try {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
|
||||
} catch (\Exception $exception) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'exception' => $exception]);
|
||||
}
|
||||
}
|
||||
DBA::close($items);
|
||||
|
|
|
@ -99,8 +99,8 @@ class PublicTimeline extends BaseApi
|
|||
self::setBoundaries($item['uri-id']);
|
||||
try {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
|
||||
} catch (\Exception $exception) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'exception' => $exception]);
|
||||
}
|
||||
}
|
||||
DBA::close($items);
|
||||
|
|
|
@ -120,8 +120,8 @@ class Tag extends BaseApi
|
|||
self::setBoundaries($item['uri-id']);
|
||||
try {
|
||||
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
|
||||
} catch (\Exception $exception) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'exception' => $exception]);
|
||||
}
|
||||
}
|
||||
DBA::close($items);
|
||||
|
|
|
@ -57,8 +57,8 @@ class Statuses extends BaseApi
|
|||
while ($status = Post::fetch($statuses)) {
|
||||
try {
|
||||
$trending[] = DI::mstdnStatus()->createFromUriId($status['uri-id'], $uid, $display_quotes);
|
||||
} catch (\Throwable $th) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $status['uri-id'], 'uid' => $uid, 'error' => $th]);
|
||||
} catch (\Exception $exception) {
|
||||
Logger::info('Post not fetchable', ['uri-id' => $status['uri-id'], 'uid' => $uid, 'exception' => $exception]);
|
||||
}
|
||||
}
|
||||
DBA::close($statuses);
|
||||
|
|
|
@ -83,13 +83,18 @@ class Proxy extends BaseModule
|
|||
$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();
|
||||
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)]);
|
||||
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 (\Exception $exception) {
|
||||
Logger::notice('Error fetching image', ['image' => $request['url'], 'exception' => $exception]);
|
||||
self::responseError();
|
||||
// stop.
|
||||
}
|
||||
|
||||
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => DI::userSession()->getLocalUserId(), 'image' => $request['url']]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue