Move jsonError out of Factory\Api\Mastodon\Error->RecordNotFound

This commit is contained in:
Hypolite Petovan 2023-10-11 09:16:03 -04:00
parent 9e71610711
commit 7f846f153d
36 changed files with 68 additions and 56 deletions

View File

@ -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'] ?? '']); $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 = $this->l10n->t('Record not found');
$error_description = ''; $error_description = '';
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(404, $error);
$this->jsonError(404, $errorObj->toArray());
} }
public function UnprocessableEntity(string $error = '') public function UnprocessableEntity(string $error = '')

View File

@ -359,7 +359,7 @@ class Status extends BaseFactory
{ {
$item = ActivityPub\Transmitter::getItemArrayFromMail($id, true); $item = ActivityPub\Transmitter::getItemArrayFromMail($id, true);
if (empty($item)) { if (empty($item)) {
$this->mstdnErrorFactory->RecordNotFound(); throw new HTTPException\NotFoundException('Mail record not found with id: ' . $id);
} }
$account = $this->mstdnAccountFactory->createFromContactId($item['author-id']); $account = $this->mstdnAccountFactory->createFromContactId($item['author-id']);

View File

@ -44,7 +44,7 @@ class Dislike extends BaseApi
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
Item::performActivity($item['id'], 'dislike', $uid); Item::performActivity($item['id'], 'dislike', $uid);

View File

@ -46,7 +46,7 @@ class DislikedBy extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) { 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]); $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::DISLIKE, 'deleted' => false]);

View File

@ -44,7 +44,7 @@ class Undislike extends BaseApi
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
Item::performActivity($item['id'], 'undislike', $uid); Item::performActivity($item['id'], 'undislike', $uid);

View File

@ -46,14 +46,14 @@ class Accounts extends BaseApi
if (!empty($this->parameters['id'])) { if (!empty($this->parameters['id'])) {
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
} else { } else {
$contact = Contact::selectFirst(['id'], ['nick' => $this->parameters['name'], 'uid' => 0]); $contact = Contact::selectFirst(['id'], ['nick' => $this->parameters['name'], 'uid' => 0]);
if (!empty($contact['id'])) { if (!empty($contact['id'])) {
$id = $contact['id']; $id = $contact['id'];
} elseif (!($id = Contact::getIdForURL($this->parameters['name'], 0, false))) { } elseif (!($id = Contact::getIdForURL($this->parameters['name'], 0, false))) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
} }

View File

@ -46,7 +46,7 @@ class Followers extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$request = $this->getRequest([ $request = $this->getRequest([

View File

@ -46,7 +46,7 @@ class Following extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$request = $this->getRequest([ $request = $this->getRequest([

View File

@ -46,7 +46,7 @@ class Lists extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$lists = []; $lists = [];

View File

@ -47,7 +47,7 @@ class Note extends BaseApi
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid); $cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
if (empty($cdata['user'])) { if (empty($cdata['user'])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]); Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]);

View File

@ -52,7 +52,7 @@ class Statuses extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$request = $this->getRequest([ $request = $this->getRequest([

View File

@ -42,7 +42,7 @@ class Unfollow extends BaseApi
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid); $cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
if (empty($cdata['user'])) { if (empty($cdata['user'])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$contact = Contact::getById($cdata['user']); $contact = Contact::getById($cdata['user']);

View File

@ -25,6 +25,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\NotFoundException;
/** /**
* @see https://docs.joinmastodon.org/methods/timelines/conversations/ * @see https://docs.joinmastodon.org/methods/timelines/conversations/
@ -83,9 +84,13 @@ class Conversations extends BaseApi
$conversations = []; $conversations = [];
while ($conv = DBA::fetch($convs)) { try {
self::setBoundaries($conv['id']); while ($conv = DBA::fetch($convs)) {
$conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']); self::setBoundaries($conv['id']);
$conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']);
}
} catch (NotFoundException $e) {
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
DBA::close($convs); DBA::close($convs);

View File

@ -25,6 +25,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\NotFoundException;
/** /**
* @see https://docs.joinmastodon.org/methods/timelines/conversations/ * @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]); 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());
}
} }
} }

View File

@ -41,7 +41,7 @@ class Lists extends BaseApi
} }
if (!Circle::exists($this->parameters['id'], $uid)) { if (!Circle::exists($this->parameters['id'], $uid)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
if (!Circle::remove($this->parameters['id'])) { if (!Circle::remove($this->parameters['id'])) {
@ -106,7 +106,7 @@ class Lists extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!Circle::exists($id, $uid)) { if (!Circle::exists($id, $uid)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$lists = DI::mstdnList()->createFromCircleId($id); $lists = DI::mstdnList()->createFromCircleId($id);
} }

View File

@ -78,7 +78,7 @@ class Accounts extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) { if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$request = $this->getRequest([ $request = $this->getRequest([

View File

@ -81,10 +81,10 @@ class Media extends BaseApi
if (empty($photo['resource-id'])) { if (empty($photo['resource-id'])) {
$media = Post\Media::getById($this->parameters['id']); $media = Post\Media::getById($this->parameters['id']);
if (empty($media['uri-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])) { 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']); Post\Media::updateById(['description' => $request['description']], $this->parameters['id']);
$this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id'])); $this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id']));
@ -109,7 +109,7 @@ class Media extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!Photo::exists(['id' => $id, 'uid' => $uid])) { if (!Photo::exists(['id' => $id, 'uid' => $uid])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($id)); $this->jsonExit(DI::mstdnAttachment()->createFromPhoto($id));

View File

@ -45,7 +45,7 @@ class Mutes extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$request = $this->getRequest([ $request = $this->getRequest([

View File

@ -50,7 +50,7 @@ class Notifications extends BaseApi
$notification = DI::notification()->selectOneForUser($uid, ['id' => $id]); $notification = DI::notification()->selectOneForUser($uid, ['id' => $id]);
$this->jsonExit(DI::mstdnNotification()->createFromNotification($notification, self::appSupportsQuotes())); $this->jsonExit(DI::mstdnNotification()->createFromNotification($notification, self::appSupportsQuotes()));
} catch (\Exception $e) { } catch (\Exception $e) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
} }

View File

@ -94,7 +94,7 @@ class PushSubscription extends BaseApi
$subscription = Subscription::select($application['id'], $uid, ['id']); $subscription = Subscription::select($application['id'], $uid, ['id']);
if (empty($subscription)) { if (empty($subscription)) {
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]); $this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]);
$this->errorFactory->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$fields = [ $fields = [
@ -145,7 +145,7 @@ class PushSubscription extends BaseApi
if (!Subscription::exists($application['id'], $uid)) { if (!Subscription::exists($application['id'], $uid)) {
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $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]); $this->logger->info('Fetch subscription', ['application-id' => $application['id'], 'uid' => $uid]);

View File

@ -51,7 +51,7 @@ class ScheduledStatuses extends BaseApi
} }
if (!DBA::exists('delayed-post', ['id' => $this->parameters['id'], 'uid' => $uid])) { 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']); Post\Delayed::deleteById($this->parameters['id']);

View File

@ -324,11 +324,11 @@ class Statuses extends BaseApi
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]); $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]);
if (empty($item['id'])) { if (empty($item['id'])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
if (!Item::markForDeletionById($item['id'])) { if (!Item::markForDeletionById($item['id'])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
$this->jsonExit([]); $this->jsonExit([]);

View File

@ -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]]); $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
if ($item['gravity'] != Item::GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
@ -56,10 +56,10 @@ class Bookmark extends BaseApi
if (!empty($stored)) { if (!empty($stored)) {
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
} else { } else {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
} }

View File

@ -116,7 +116,7 @@ class Context extends BaseApi
} }
DBA::close($posts); DBA::close($posts);
} else { } else {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
} }

View File

@ -44,7 +44,7 @@ class Favourite extends BaseApi
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
Item::performActivity($item['id'], 'like', $uid); Item::performActivity($item['id'], 'like', $uid);

View File

@ -45,7 +45,7 @@ class FavouritedBy extends BaseApi
} }
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { 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]); $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]);

View File

@ -44,7 +44,7 @@ class Mute extends BaseApi
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
if ($item['gravity'] != Item::GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {

View File

@ -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]]); $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { 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); Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], $uid);

View File

@ -47,7 +47,7 @@ class Reblog extends BaseApi
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
if ($item['network'] == Protocol::DIASPORA) { if ($item['network'] == Protocol::DIASPORA) {

View File

@ -45,7 +45,7 @@ class RebloggedBy extends BaseApi
} }
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { 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]); $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]);

View File

@ -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]]); $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
if ($item['gravity'] != Item::GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {
@ -56,10 +56,10 @@ class Unbookmark extends BaseApi
if (!empty($stored)) { if (!empty($stored)) {
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
} else { } else {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
} }

View File

@ -44,7 +44,7 @@ class Unfavourite extends BaseApi
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
Item::performActivity($item['id'], 'unlike', $uid); Item::performActivity($item['id'], 'unlike', $uid);

View File

@ -44,7 +44,7 @@ class Unmute extends BaseApi
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
if ($item['gravity'] != Item::GRAVITY_PARENT) { if ($item['gravity'] != Item::GRAVITY_PARENT) {

View File

@ -43,7 +43,7 @@ class Unpin extends BaseApi
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid); Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid);

View File

@ -46,17 +46,17 @@ class Unreblog extends BaseApi
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
if ($item['network'] == Protocol::DIASPORA) { if ($item['network'] == Protocol::DIASPORA) {
$item = Post::selectFirstForUser($uid, ['id'], ['quote-uri-id' => $this->parameters['id'], 'body' => '', 'origin' => true, 'uid' => $uid]); $item = Post::selectFirstForUser($uid, ['id'], ['quote-uri-id' => $this->parameters['id'], 'body' => '', 'origin' => true, 'uid' => $uid]);
if (empty($item['id'])) { if (empty($item['id'])) {
DI::mstdnError()->RecordNotFound(); $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
} }
if (!Item::markForDeletionById($item['id'])) { 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])) { } 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']))); DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])));

View File

@ -26,6 +26,7 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\NotFoundException;
/** /**
* @see https://docs.joinmastodon.org/methods/timelines/ * @see https://docs.joinmastodon.org/methods/timelines/
@ -76,9 +77,13 @@ class Direct extends BaseApi
$statuses = []; $statuses = [];
while ($mail = DBA::fetch($mails)) { try {
self::setBoundaries($mail['uri-id']); while ($mail = DBA::fetch($mails)) {
$statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']); 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'])) { if (!empty($request['min_id'])) {