From 7f846f153d6abf8ed4c0f9a5b81bd45a6ac8e4a2 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Oct 2023 09:16:03 -0400 Subject: [PATCH] Move jsonError out of Factory\Api\Mastodon\Error->RecordNotFound --- src/Factory/Api/Mastodon/Error.php | 7 ++----- src/Factory/Api/Mastodon/Status.php | 2 +- src/Module/Api/Friendica/Statuses/Dislike.php | 2 +- src/Module/Api/Friendica/Statuses/DislikedBy.php | 2 +- src/Module/Api/Friendica/Statuses/Undislike.php | 2 +- src/Module/Api/Mastodon/Accounts.php | 4 ++-- src/Module/Api/Mastodon/Accounts/Followers.php | 2 +- src/Module/Api/Mastodon/Accounts/Following.php | 2 +- src/Module/Api/Mastodon/Accounts/Lists.php | 2 +- src/Module/Api/Mastodon/Accounts/Note.php | 2 +- src/Module/Api/Mastodon/Accounts/Statuses.php | 2 +- src/Module/Api/Mastodon/Accounts/Unfollow.php | 2 +- src/Module/Api/Mastodon/Conversations.php | 11 ++++++++--- src/Module/Api/Mastodon/Conversations/Read.php | 7 ++++++- src/Module/Api/Mastodon/Lists.php | 4 ++-- src/Module/Api/Mastodon/Lists/Accounts.php | 2 +- src/Module/Api/Mastodon/Media.php | 6 +++--- src/Module/Api/Mastodon/Mutes.php | 2 +- src/Module/Api/Mastodon/Notifications.php | 2 +- src/Module/Api/Mastodon/PushSubscription.php | 4 ++-- src/Module/Api/Mastodon/ScheduledStatuses.php | 2 +- src/Module/Api/Mastodon/Statuses.php | 4 ++-- src/Module/Api/Mastodon/Statuses/Bookmark.php | 6 +++--- src/Module/Api/Mastodon/Statuses/Context.php | 2 +- src/Module/Api/Mastodon/Statuses/Favourite.php | 2 +- src/Module/Api/Mastodon/Statuses/FavouritedBy.php | 2 +- src/Module/Api/Mastodon/Statuses/Mute.php | 2 +- src/Module/Api/Mastodon/Statuses/Pin.php | 2 +- src/Module/Api/Mastodon/Statuses/Reblog.php | 2 +- src/Module/Api/Mastodon/Statuses/RebloggedBy.php | 2 +- src/Module/Api/Mastodon/Statuses/Unbookmark.php | 6 +++--- src/Module/Api/Mastodon/Statuses/Unfavourite.php | 2 +- src/Module/Api/Mastodon/Statuses/Unmute.php | 2 +- src/Module/Api/Mastodon/Statuses/Unpin.php | 2 +- src/Module/Api/Mastodon/Statuses/Unreblog.php | 6 +++--- src/Module/Api/Mastodon/Timelines/Direct.php | 11 ++++++++--- 36 files changed, 68 insertions(+), 56 deletions(-) diff --git a/src/Factory/Api/Mastodon/Error.php b/src/Factory/Api/Mastodon/Error.php index 68172d6323..dec56ba90f 100644 --- a/src/Factory/Api/Mastodon/Error.php +++ b/src/Factory/Api/Mastodon/Error.php @@ -50,14 +50,11 @@ class Error extends BaseFactory $this->logger->info('API Error', ['no' => $errorno, 'error' => $error, 'method' => $this->args->getMethod(), 'command' => $this->args->getQueryString(), 'user-agent' => $this->server['HTTP_USER_AGENT'] ?? '']); } - public function RecordNotFound() + public function RecordNotFound(): \Friendica\Object\Api\Mastodon\Error { $error = $this->l10n->t('Record not found'); $error_description = ''; - $errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); - - $this->logError(404, $error); - $this->jsonError(404, $errorObj->toArray()); + return new \Friendica\Object\Api\Mastodon\Error($error, $error_description); } public function UnprocessableEntity(string $error = '') diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index b53d846fcd..4bf5609b9a 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -359,7 +359,7 @@ class Status extends BaseFactory { $item = ActivityPub\Transmitter::getItemArrayFromMail($id, true); if (empty($item)) { - $this->mstdnErrorFactory->RecordNotFound(); + throw new HTTPException\NotFoundException('Mail record not found with id: ' . $id); } $account = $this->mstdnAccountFactory->createFromContactId($item['author-id']); diff --git a/src/Module/Api/Friendica/Statuses/Dislike.php b/src/Module/Api/Friendica/Statuses/Dislike.php index 5491bf1890..a0dcd7077d 100644 --- a/src/Module/Api/Friendica/Statuses/Dislike.php +++ b/src/Module/Api/Friendica/Statuses/Dislike.php @@ -44,7 +44,7 @@ class Dislike extends BaseApi $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } Item::performActivity($item['id'], 'dislike', $uid); diff --git a/src/Module/Api/Friendica/Statuses/DislikedBy.php b/src/Module/Api/Friendica/Statuses/DislikedBy.php index bb78884837..fcae9990ce 100644 --- a/src/Module/Api/Friendica/Statuses/DislikedBy.php +++ b/src/Module/Api/Friendica/Statuses/DislikedBy.php @@ -46,7 +46,7 @@ class DislikedBy extends BaseApi $id = $this->parameters['id']; if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::DISLIKE, 'deleted' => false]); diff --git a/src/Module/Api/Friendica/Statuses/Undislike.php b/src/Module/Api/Friendica/Statuses/Undislike.php index a646045e53..f304fb9db9 100644 --- a/src/Module/Api/Friendica/Statuses/Undislike.php +++ b/src/Module/Api/Friendica/Statuses/Undislike.php @@ -44,7 +44,7 @@ class Undislike extends BaseApi $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } Item::performActivity($item['id'], 'undislike', $uid); diff --git a/src/Module/Api/Mastodon/Accounts.php b/src/Module/Api/Mastodon/Accounts.php index bd215e3873..4ebd0d4bd3 100644 --- a/src/Module/Api/Mastodon/Accounts.php +++ b/src/Module/Api/Mastodon/Accounts.php @@ -46,14 +46,14 @@ class Accounts extends BaseApi if (!empty($this->parameters['id'])) { $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } } else { $contact = Contact::selectFirst(['id'], ['nick' => $this->parameters['name'], 'uid' => 0]); if (!empty($contact['id'])) { $id = $contact['id']; } elseif (!($id = Contact::getIdForURL($this->parameters['name'], 0, false))) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/Accounts/Followers.php b/src/Module/Api/Mastodon/Accounts/Followers.php index e433943c8f..22b99ee4d6 100644 --- a/src/Module/Api/Mastodon/Accounts/Followers.php +++ b/src/Module/Api/Mastodon/Accounts/Followers.php @@ -46,7 +46,7 @@ class Followers extends BaseApi $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Accounts/Following.php b/src/Module/Api/Mastodon/Accounts/Following.php index 3b19e1eedc..0fde1404e3 100644 --- a/src/Module/Api/Mastodon/Accounts/Following.php +++ b/src/Module/Api/Mastodon/Accounts/Following.php @@ -46,7 +46,7 @@ class Following extends BaseApi $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Accounts/Lists.php b/src/Module/Api/Mastodon/Accounts/Lists.php index 4a494838b0..f0187a2861 100644 --- a/src/Module/Api/Mastodon/Accounts/Lists.php +++ b/src/Module/Api/Mastodon/Accounts/Lists.php @@ -46,7 +46,7 @@ class Lists extends BaseApi $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $lists = []; diff --git a/src/Module/Api/Mastodon/Accounts/Note.php b/src/Module/Api/Mastodon/Accounts/Note.php index 24df3b3578..52c76ab693 100644 --- a/src/Module/Api/Mastodon/Accounts/Note.php +++ b/src/Module/Api/Mastodon/Accounts/Note.php @@ -47,7 +47,7 @@ class Note extends BaseApi $cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid); if (empty($cdata['user'])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]); diff --git a/src/Module/Api/Mastodon/Accounts/Statuses.php b/src/Module/Api/Mastodon/Accounts/Statuses.php index 93b642cd69..599a2eff8a 100644 --- a/src/Module/Api/Mastodon/Accounts/Statuses.php +++ b/src/Module/Api/Mastodon/Accounts/Statuses.php @@ -52,7 +52,7 @@ class Statuses extends BaseApi $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Accounts/Unfollow.php b/src/Module/Api/Mastodon/Accounts/Unfollow.php index 83676f25a2..cfe3b3cb1e 100644 --- a/src/Module/Api/Mastodon/Accounts/Unfollow.php +++ b/src/Module/Api/Mastodon/Accounts/Unfollow.php @@ -42,7 +42,7 @@ class Unfollow extends BaseApi $cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid); if (empty($cdata['user'])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $contact = Contact::getById($cdata['user']); diff --git a/src/Module/Api/Mastodon/Conversations.php b/src/Module/Api/Mastodon/Conversations.php index 71239a0ff1..c45144c98d 100644 --- a/src/Module/Api/Mastodon/Conversations.php +++ b/src/Module/Api/Mastodon/Conversations.php @@ -25,6 +25,7 @@ use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\BaseApi; +use Friendica\Network\HTTPException\NotFoundException; /** * @see https://docs.joinmastodon.org/methods/timelines/conversations/ @@ -83,9 +84,13 @@ class Conversations extends BaseApi $conversations = []; - while ($conv = DBA::fetch($convs)) { - self::setBoundaries($conv['id']); - $conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']); + try { + while ($conv = DBA::fetch($convs)) { + self::setBoundaries($conv['id']); + $conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']); + } + } catch (NotFoundException $e) { + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } DBA::close($convs); diff --git a/src/Module/Api/Mastodon/Conversations/Read.php b/src/Module/Api/Mastodon/Conversations/Read.php index 5bb7b3526c..86a5090e37 100644 --- a/src/Module/Api/Mastodon/Conversations/Read.php +++ b/src/Module/Api/Mastodon/Conversations/Read.php @@ -25,6 +25,7 @@ use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\BaseApi; +use Friendica\Network\HTTPException\NotFoundException; /** * @see https://docs.joinmastodon.org/methods/timelines/conversations/ @@ -42,6 +43,10 @@ class Read extends BaseApi DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]); - $this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray()); + try { + $this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray()); + } catch (NotFoundException $e) { + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + } } } diff --git a/src/Module/Api/Mastodon/Lists.php b/src/Module/Api/Mastodon/Lists.php index 571927a168..9d9e6955b1 100644 --- a/src/Module/Api/Mastodon/Lists.php +++ b/src/Module/Api/Mastodon/Lists.php @@ -41,7 +41,7 @@ class Lists extends BaseApi } if (!Circle::exists($this->parameters['id'], $uid)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if (!Circle::remove($this->parameters['id'])) { @@ -106,7 +106,7 @@ class Lists extends BaseApi $id = $this->parameters['id']; if (!Circle::exists($id, $uid)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $lists = DI::mstdnList()->createFromCircleId($id); } diff --git a/src/Module/Api/Mastodon/Lists/Accounts.php b/src/Module/Api/Mastodon/Lists/Accounts.php index 135701904e..ffa63caf44 100644 --- a/src/Module/Api/Mastodon/Lists/Accounts.php +++ b/src/Module/Api/Mastodon/Lists/Accounts.php @@ -78,7 +78,7 @@ class Accounts extends BaseApi $id = $this->parameters['id']; if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Media.php b/src/Module/Api/Mastodon/Media.php index b2424f0227..91c88ee181 100644 --- a/src/Module/Api/Mastodon/Media.php +++ b/src/Module/Api/Mastodon/Media.php @@ -81,10 +81,10 @@ class Media extends BaseApi if (empty($photo['resource-id'])) { $media = Post\Media::getById($this->parameters['id']); if (empty($media['uri-id'])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if (!Post::exists(['uri-id' => $media['uri-id'], 'uid' => $uid, 'origin' => true])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } Post\Media::updateById(['description' => $request['description']], $this->parameters['id']); $this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id'])); @@ -109,7 +109,7 @@ class Media extends BaseApi $id = $this->parameters['id']; if (!Photo::exists(['id' => $id, 'uid' => $uid])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $this->jsonExit(DI::mstdnAttachment()->createFromPhoto($id)); diff --git a/src/Module/Api/Mastodon/Mutes.php b/src/Module/Api/Mastodon/Mutes.php index 177b618776..71b1949f57 100644 --- a/src/Module/Api/Mastodon/Mutes.php +++ b/src/Module/Api/Mastodon/Mutes.php @@ -45,7 +45,7 @@ class Mutes extends BaseApi $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Notifications.php b/src/Module/Api/Mastodon/Notifications.php index ee3a253b3d..6045d24653 100644 --- a/src/Module/Api/Mastodon/Notifications.php +++ b/src/Module/Api/Mastodon/Notifications.php @@ -50,7 +50,7 @@ class Notifications extends BaseApi $notification = DI::notification()->selectOneForUser($uid, ['id' => $id]); $this->jsonExit(DI::mstdnNotification()->createFromNotification($notification, self::appSupportsQuotes())); } catch (\Exception $e) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/PushSubscription.php b/src/Module/Api/Mastodon/PushSubscription.php index a03d0250cc..b91f8e7ba3 100644 --- a/src/Module/Api/Mastodon/PushSubscription.php +++ b/src/Module/Api/Mastodon/PushSubscription.php @@ -94,7 +94,7 @@ class PushSubscription extends BaseApi $subscription = Subscription::select($application['id'], $uid, ['id']); if (empty($subscription)) { $this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]); - $this->errorFactory->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $fields = [ @@ -145,7 +145,7 @@ class PushSubscription extends BaseApi if (!Subscription::exists($application['id'], $uid)) { $this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]); - $this->errorFactory->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $this->logger->info('Fetch subscription', ['application-id' => $application['id'], 'uid' => $uid]); diff --git a/src/Module/Api/Mastodon/ScheduledStatuses.php b/src/Module/Api/Mastodon/ScheduledStatuses.php index 5204ab5563..f136c2708f 100644 --- a/src/Module/Api/Mastodon/ScheduledStatuses.php +++ b/src/Module/Api/Mastodon/ScheduledStatuses.php @@ -51,7 +51,7 @@ class ScheduledStatuses extends BaseApi } if (!DBA::exists('delayed-post', ['id' => $this->parameters['id'], 'uid' => $uid])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } Post\Delayed::deleteById($this->parameters['id']); diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index 749e0aa39f..0940befbad 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -324,11 +324,11 @@ class Statuses extends BaseApi $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]); if (empty($item['id'])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if (!Item::markForDeletionById($item['id'])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $this->jsonExit([]); diff --git a/src/Module/Api/Mastodon/Statuses/Bookmark.php b/src/Module/Api/Mastodon/Statuses/Bookmark.php index f2e5ff40d4..1ba0d6e040 100644 --- a/src/Module/Api/Mastodon/Statuses/Bookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Bookmark.php @@ -44,7 +44,7 @@ class Bookmark extends BaseApi $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if ($item['gravity'] != Item::GRAVITY_PARENT) { @@ -56,10 +56,10 @@ class Bookmark extends BaseApi if (!empty($stored)) { $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } } else { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php index 3a73569f40..c171c0ccae 100644 --- a/src/Module/Api/Mastodon/Statuses/Context.php +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -116,7 +116,7 @@ class Context extends BaseApi } DBA::close($posts); } else { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Favourite.php b/src/Module/Api/Mastodon/Statuses/Favourite.php index d8cf8054ee..384abc3d82 100644 --- a/src/Module/Api/Mastodon/Statuses/Favourite.php +++ b/src/Module/Api/Mastodon/Statuses/Favourite.php @@ -44,7 +44,7 @@ class Favourite extends BaseApi $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } Item::performActivity($item['id'], 'like', $uid); diff --git a/src/Module/Api/Mastodon/Statuses/FavouritedBy.php b/src/Module/Api/Mastodon/Statuses/FavouritedBy.php index b6902a1c02..bce95610a9 100644 --- a/src/Module/Api/Mastodon/Statuses/FavouritedBy.php +++ b/src/Module/Api/Mastodon/Statuses/FavouritedBy.php @@ -45,7 +45,7 @@ class FavouritedBy extends BaseApi } if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]); diff --git a/src/Module/Api/Mastodon/Statuses/Mute.php b/src/Module/Api/Mastodon/Statuses/Mute.php index d282770dfd..68491c8b70 100644 --- a/src/Module/Api/Mastodon/Statuses/Mute.php +++ b/src/Module/Api/Mastodon/Statuses/Mute.php @@ -44,7 +44,7 @@ class Mute extends BaseApi $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if ($item['gravity'] != Item::GRAVITY_PARENT) { diff --git a/src/Module/Api/Mastodon/Statuses/Pin.php b/src/Module/Api/Mastodon/Statuses/Pin.php index d9f95132c3..99f097740f 100644 --- a/src/Module/Api/Mastodon/Statuses/Pin.php +++ b/src/Module/Api/Mastodon/Statuses/Pin.php @@ -43,7 +43,7 @@ class Pin extends BaseApi $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], $uid); diff --git a/src/Module/Api/Mastodon/Statuses/Reblog.php b/src/Module/Api/Mastodon/Statuses/Reblog.php index 6c368b019a..3e37a94a7d 100644 --- a/src/Module/Api/Mastodon/Statuses/Reblog.php +++ b/src/Module/Api/Mastodon/Statuses/Reblog.php @@ -47,7 +47,7 @@ class Reblog extends BaseApi $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if ($item['network'] == Protocol::DIASPORA) { diff --git a/src/Module/Api/Mastodon/Statuses/RebloggedBy.php b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php index ff0e1ba94e..9c508e42a9 100644 --- a/src/Module/Api/Mastodon/Statuses/RebloggedBy.php +++ b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php @@ -45,7 +45,7 @@ class RebloggedBy extends BaseApi } if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]); diff --git a/src/Module/Api/Mastodon/Statuses/Unbookmark.php b/src/Module/Api/Mastodon/Statuses/Unbookmark.php index 36902fb218..4eccc97b2e 100644 --- a/src/Module/Api/Mastodon/Statuses/Unbookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Unbookmark.php @@ -44,7 +44,7 @@ class Unbookmark extends BaseApi $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if ($item['gravity'] != Item::GRAVITY_PARENT) { @@ -56,10 +56,10 @@ class Unbookmark extends BaseApi if (!empty($stored)) { $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } } else { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Unfavourite.php b/src/Module/Api/Mastodon/Statuses/Unfavourite.php index c6a924b2a4..ada587b2fe 100644 --- a/src/Module/Api/Mastodon/Statuses/Unfavourite.php +++ b/src/Module/Api/Mastodon/Statuses/Unfavourite.php @@ -44,7 +44,7 @@ class Unfavourite extends BaseApi $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } Item::performActivity($item['id'], 'unlike', $uid); diff --git a/src/Module/Api/Mastodon/Statuses/Unmute.php b/src/Module/Api/Mastodon/Statuses/Unmute.php index edf14925d0..511ae15407 100644 --- a/src/Module/Api/Mastodon/Statuses/Unmute.php +++ b/src/Module/Api/Mastodon/Statuses/Unmute.php @@ -44,7 +44,7 @@ class Unmute extends BaseApi $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if ($item['gravity'] != Item::GRAVITY_PARENT) { diff --git a/src/Module/Api/Mastodon/Statuses/Unpin.php b/src/Module/Api/Mastodon/Statuses/Unpin.php index 0f5d44afac..c11f89f6e0 100644 --- a/src/Module/Api/Mastodon/Statuses/Unpin.php +++ b/src/Module/Api/Mastodon/Statuses/Unpin.php @@ -43,7 +43,7 @@ class Unpin extends BaseApi $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid); diff --git a/src/Module/Api/Mastodon/Statuses/Unreblog.php b/src/Module/Api/Mastodon/Statuses/Unreblog.php index 4f72eac25d..c99011ae43 100644 --- a/src/Module/Api/Mastodon/Statuses/Unreblog.php +++ b/src/Module/Api/Mastodon/Statuses/Unreblog.php @@ -46,17 +46,17 @@ class Unreblog extends BaseApi $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if ($item['network'] == Protocol::DIASPORA) { $item = Post::selectFirstForUser($uid, ['id'], ['quote-uri-id' => $this->parameters['id'], 'body' => '', 'origin' => true, 'uid' => $uid]); if (empty($item['id'])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if (!Item::markForDeletionById($item['id'])) { - DI::mstdnError()->RecordNotFound(); + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } } elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) { DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network']))); diff --git a/src/Module/Api/Mastodon/Timelines/Direct.php b/src/Module/Api/Mastodon/Timelines/Direct.php index c1e7109709..730b639104 100644 --- a/src/Module/Api/Mastodon/Timelines/Direct.php +++ b/src/Module/Api/Mastodon/Timelines/Direct.php @@ -26,6 +26,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\BaseApi; use Friendica\Network\HTTPException; +use Friendica\Network\HTTPException\NotFoundException; /** * @see https://docs.joinmastodon.org/methods/timelines/ @@ -76,9 +77,13 @@ class Direct extends BaseApi $statuses = []; - while ($mail = DBA::fetch($mails)) { - self::setBoundaries($mail['uri-id']); - $statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']); + try { + while ($mail = DBA::fetch($mails)) { + self::setBoundaries($mail['uri-id']); + $statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']); + } + } catch (NotFoundException $e) { + $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); } if (!empty($request['min_id'])) {