From 3e8c38946dc83f4905872610684bcf5ed73ee99d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 25 Jan 2023 23:03:51 +0000 Subject: [PATCH] Catch not fetchable posts --- src/Factory/Api/Mastodon/Status.php | 22 ++++++++++++++++--- src/Module/Api/Mastodon/Bookmarks.php | 7 +++++- src/Module/Api/Mastodon/Favourited.php | 7 +++++- src/Module/Api/Mastodon/Search.php | 7 +++++- src/Module/Api/Mastodon/Timelines/Home.php | 7 +++++- .../Api/Mastodon/Timelines/ListTimeline.php | 7 +++++- src/Module/Api/Mastodon/Timelines/Tag.php | 7 +++++- src/Module/Api/Mastodon/Trends/Statuses.php | 7 +++++- 8 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index ad2d9bab35..acc7afeb5e 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -25,6 +25,7 @@ use Friendica\BaseFactory; use Friendica\Content\ContactSelector; use Friendica\Content\Item as ContentItem; use Friendica\Content\Text\BBCode; +use Friendica\Core\Logger; use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\Model\Item; @@ -249,13 +250,23 @@ class Status extends BaseFactory } if ($is_reshare) { - $reshare = $this->createFromUriId($uriId, $uid, $display_quote, false, false)->toArray(); + try { + $reshare = $this->createFromUriId($uriId, $uid, $display_quote, false, false)->toArray(); + } catch (\Throwable $th) { + Logger::info('Reshare not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]); + $reshare = []; + } } else { $reshare = []; } if ($in_reply_status && ($item['gravity'] == Item::GRAVITY_COMMENT)) { - $in_reply = $this->createFromUriId($item['thr-parent-id'], $uid, $display_quote, false, false)->toArray(); + try { + $in_reply = $this->createFromUriId($item['thr-parent-id'], $uid, $display_quote, false, false)->toArray(); + } catch (\Throwable $th) { + Logger::info('Reply post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]); + $in_reply = []; + } } else { $in_reply = []; } @@ -283,7 +294,12 @@ class Status extends BaseFactory } if (!empty($quote_id)) { - $quote = $this->createFromUriId($quote_id, $uid, false, false, false)->toArray(); + try { + $quote = $this->createFromUriId($quote_id, $uid, false, false, false)->toArray(); + } catch (\Throwable $th) { + Logger::info('Quote not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]); + $quote = []; + } } else { $quote = []; } diff --git a/src/Module/Api/Mastodon/Bookmarks.php b/src/Module/Api/Mastodon/Bookmarks.php index 411e8b1d06..615bfc501f 100644 --- a/src/Module/Api/Mastodon/Bookmarks.php +++ b/src/Module/Api/Mastodon/Bookmarks.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon; +use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -74,7 +75,11 @@ class Bookmarks extends BaseApi $statuses = []; while ($item = Post::fetch($items)) { self::setBoundaries($item['uri-id']); - $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes); + 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]); + } } DBA::close($items); diff --git a/src/Module/Api/Mastodon/Favourited.php b/src/Module/Api/Mastodon/Favourited.php index dfbaa0ded5..93c9ef2436 100644 --- a/src/Module/Api/Mastodon/Favourited.php +++ b/src/Module/Api/Mastodon/Favourited.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon; +use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -76,7 +77,11 @@ class Favourited extends BaseApi $statuses = []; while ($item = Post::fetch($items)) { self::setBoundaries($item['thr-parent-id']); - $statuses[] = DI::mstdnStatus()->createFromUriId($item['thr-parent-id'], $uid, $display_quotes); + 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]); + } } DBA::close($items); diff --git a/src/Module/Api/Mastodon/Search.php b/src/Module/Api/Mastodon/Search.php index a991052c7f..07d1daa19e 100644 --- a/src/Module/Api/Mastodon/Search.php +++ b/src/Module/Api/Mastodon/Search.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon; +use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; @@ -181,7 +182,11 @@ class Search extends BaseApi $statuses = []; while ($item = Post::fetch($items)) { self::setBoundaries($item['uri-id']); - $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes); + 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]); + } } DBA::close($items); diff --git a/src/Module/Api/Mastodon/Timelines/Home.php b/src/Module/Api/Mastodon/Timelines/Home.php index a72957b9d8..5efaf4930e 100644 --- a/src/Module/Api/Mastodon/Timelines/Home.php +++ b/src/Module/Api/Mastodon/Timelines/Home.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon\Timelines; +use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -96,7 +97,11 @@ class Home extends BaseApi $statuses = []; while ($item = Post::fetch($items)) { self::setBoundaries($item['uri-id']); - $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes); + 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]); + } } DBA::close($items); diff --git a/src/Module/Api/Mastodon/Timelines/ListTimeline.php b/src/Module/Api/Mastodon/Timelines/ListTimeline.php index 83ab204e7b..a8de13056e 100644 --- a/src/Module/Api/Mastodon/Timelines/ListTimeline.php +++ b/src/Module/Api/Mastodon/Timelines/ListTimeline.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon\Timelines; +use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -101,7 +102,11 @@ class ListTimeline extends BaseApi $statuses = []; while ($item = Post::fetch($items)) { self::setBoundaries($item['uri-id']); - $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes); + 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]); + } } DBA::close($items); diff --git a/src/Module/Api/Mastodon/Timelines/Tag.php b/src/Module/Api/Mastodon/Timelines/Tag.php index c5a06e28c2..1d04dec625 100644 --- a/src/Module/Api/Mastodon/Timelines/Tag.php +++ b/src/Module/Api/Mastodon/Timelines/Tag.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon\Timelines; +use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; @@ -110,7 +111,11 @@ class Tag extends BaseApi $statuses = []; while ($item = Post::fetch($items)) { self::setBoundaries($item['uri-id']); - $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes); + 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]); + } } DBA::close($items); diff --git a/src/Module/Api/Mastodon/Trends/Statuses.php b/src/Module/Api/Mastodon/Trends/Statuses.php index 7fad480cb0..cf287e59c3 100644 --- a/src/Module/Api/Mastodon/Trends/Statuses.php +++ b/src/Module/Api/Mastodon/Trends/Statuses.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon\Trends; +use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; @@ -53,7 +54,11 @@ class Statuses extends BaseApi $trending = []; $statuses = Post::selectPostThread(['uri-id'], $condition, ['limit' => $request['limit'], 'order' => ['total-actors' => true]]); while ($status = Post::fetch($statuses)) { - $trending[] = DI::mstdnStatus()->createFromUriId($status['uri-id'], $uid, $display_quotes); + 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]); + } } DBA::close($statuses); -- 2.39.5