diff --git a/src/Module/Api/Friendica/Statuses/Dislike.php b/src/Module/Api/Friendica/Statuses/Dislike.php index 99c8eb857a..c436c85469 100644 --- a/src/Module/Api/Friendica/Statuses/Dislike.php +++ b/src/Module/Api/Friendica/Statuses/Dislike.php @@ -39,12 +39,12 @@ class Dislike extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 3c13120873..f6470330d5 100644 --- a/src/Module/Api/Friendica/Statuses/DislikedBy.php +++ b/src/Module/Api/Friendica/Statuses/DislikedBy.php @@ -41,12 +41,12 @@ class DislikedBy extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 5387f1b105..ba53f902b2 100644 --- a/src/Module/Api/Friendica/Statuses/Undislike.php +++ b/src/Module/Api/Friendica/Statuses/Undislike.php @@ -39,12 +39,12 @@ class Undislike extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 6b88b84ef3..fcf443056d 100644 --- a/src/Module/Api/Mastodon/Accounts.php +++ b/src/Module/Api/Mastodon/Accounts.php @@ -40,20 +40,20 @@ class Accounts extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id']) && empty($this->parameters['name'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } if (!empty($this->parameters['id'])) { $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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))) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/Accounts/Block.php b/src/Module/Api/Mastodon/Accounts/Block.php index 1582f3299c..f6970336d5 100644 --- a/src/Module/Api/Mastodon/Accounts/Block.php +++ b/src/Module/Api/Mastodon/Accounts/Block.php @@ -38,7 +38,7 @@ class Block extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } Contact\User::setBlocked($this->parameters['id'], $uid, true); diff --git a/src/Module/Api/Mastodon/Accounts/Follow.php b/src/Module/Api/Mastodon/Accounts/Follow.php index 272b989ee4..0f565d580c 100644 --- a/src/Module/Api/Mastodon/Accounts/Follow.php +++ b/src/Module/Api/Mastodon/Accounts/Follow.php @@ -37,7 +37,7 @@ class Follow extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Accounts/Followers.php b/src/Module/Api/Mastodon/Accounts/Followers.php index 19f2a43883..0ad6f9667c 100644 --- a/src/Module/Api/Mastodon/Accounts/Followers.php +++ b/src/Module/Api/Mastodon/Accounts/Followers.php @@ -41,12 +41,12 @@ class Followers extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 061e22663d..bd88328603 100644 --- a/src/Module/Api/Mastodon/Accounts/Following.php +++ b/src/Module/Api/Mastodon/Accounts/Following.php @@ -41,12 +41,12 @@ class Following extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 8fdcade664..750ebd6810 100644 --- a/src/Module/Api/Mastodon/Accounts/Lists.php +++ b/src/Module/Api/Mastodon/Accounts/Lists.php @@ -41,12 +41,12 @@ class Lists extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } $lists = []; diff --git a/src/Module/Api/Mastodon/Accounts/Mute.php b/src/Module/Api/Mastodon/Accounts/Mute.php index ea8d0ce309..4602b18caa 100644 --- a/src/Module/Api/Mastodon/Accounts/Mute.php +++ b/src/Module/Api/Mastodon/Accounts/Mute.php @@ -37,7 +37,7 @@ class Mute extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } Contact\User::setIgnored($this->parameters['id'], $uid, true); diff --git a/src/Module/Api/Mastodon/Accounts/Note.php b/src/Module/Api/Mastodon/Accounts/Note.php index 72a7e0838d..9f36009319 100644 --- a/src/Module/Api/Mastodon/Accounts/Note.php +++ b/src/Module/Api/Mastodon/Accounts/Note.php @@ -38,7 +38,7 @@ class Note extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $request = $this->getRequest([ @@ -47,7 +47,7 @@ class Note extends BaseApi $cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid); if (empty($cdata['user'])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]); diff --git a/src/Module/Api/Mastodon/Accounts/Relationships.php b/src/Module/Api/Mastodon/Accounts/Relationships.php index f757151724..8c630d7239 100644 --- a/src/Module/Api/Mastodon/Accounts/Relationships.php +++ b/src/Module/Api/Mastodon/Accounts/Relationships.php @@ -44,7 +44,7 @@ class Relationships extends BaseApi ], $request); if (empty($request['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } if (!is_array($request['id'])) { diff --git a/src/Module/Api/Mastodon/Accounts/Statuses.php b/src/Module/Api/Mastodon/Accounts/Statuses.php index fd8fbcdab1..b4e09b613e 100644 --- a/src/Module/Api/Mastodon/Accounts/Statuses.php +++ b/src/Module/Api/Mastodon/Accounts/Statuses.php @@ -47,12 +47,12 @@ class Statuses extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Accounts/Unblock.php b/src/Module/Api/Mastodon/Accounts/Unblock.php index f2e2f2e411..0d44c52d1d 100644 --- a/src/Module/Api/Mastodon/Accounts/Unblock.php +++ b/src/Module/Api/Mastodon/Accounts/Unblock.php @@ -37,7 +37,7 @@ class Unblock extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } Contact\User::setBlocked($this->parameters['id'], $uid, false); diff --git a/src/Module/Api/Mastodon/Accounts/Unfollow.php b/src/Module/Api/Mastodon/Accounts/Unfollow.php index 6a3c68cb32..6a19267b3f 100644 --- a/src/Module/Api/Mastodon/Accounts/Unfollow.php +++ b/src/Module/Api/Mastodon/Accounts/Unfollow.php @@ -37,12 +37,12 @@ class Unfollow extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid); if (empty($cdata['user'])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } $contact = Contact::getById($cdata['user']); diff --git a/src/Module/Api/Mastodon/Accounts/Unmute.php b/src/Module/Api/Mastodon/Accounts/Unmute.php index 651233daed..689398d10f 100644 --- a/src/Module/Api/Mastodon/Accounts/Unmute.php +++ b/src/Module/Api/Mastodon/Accounts/Unmute.php @@ -37,7 +37,7 @@ class Unmute extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } Contact\User::setIgnored($this->parameters['id'], $uid, false); diff --git a/src/Module/Api/Mastodon/Apps.php b/src/Module/Api/Mastodon/Apps.php index 5ebe3e2aba..012a2b1c27 100644 --- a/src/Module/Api/Mastodon/Apps.php +++ b/src/Module/Api/Mastodon/Apps.php @@ -70,7 +70,7 @@ class Apps extends BaseApi } if (empty($request['client_name']) || empty($request['redirect_uris'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters'))); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters'))); } $client_id = bin2hex(random_bytes(32)); @@ -92,7 +92,7 @@ class Apps extends BaseApi } if (!DBA::insert('application', $fields)) { - $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); + $this->logAndJsonError(500, $this->errorFactory->InternalError()); } $this->jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray()); diff --git a/src/Module/Api/Mastodon/Apps/VerifyCredentials.php b/src/Module/Api/Mastodon/Apps/VerifyCredentials.php index 69d470306a..42e8111e77 100644 --- a/src/Module/Api/Mastodon/Apps/VerifyCredentials.php +++ b/src/Module/Api/Mastodon/Apps/VerifyCredentials.php @@ -36,7 +36,7 @@ class VerifyCredentials extends BaseApi $application = self::getCurrentApplication(); if (empty($application['id'])) { - $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized()); + $this->logAndJsonError(401, $this->errorFactory->Unauthorized()); } $this->jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id'])); diff --git a/src/Module/Api/Mastodon/Conversations.php b/src/Module/Api/Mastodon/Conversations.php index 532db4bcda..1814922c79 100644 --- a/src/Module/Api/Mastodon/Conversations.php +++ b/src/Module/Api/Mastodon/Conversations.php @@ -38,7 +38,7 @@ class Conversations extends BaseApi $uid = self::getCurrentUserID(); if (!empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } DBA::delete('conv', ['id' => $this->parameters['id'], 'uid' => $uid]); @@ -90,7 +90,7 @@ class Conversations extends BaseApi $conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']); } } catch (NotFoundException $e) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 2e876fcb5d..b78fdf8eda 100644 --- a/src/Module/Api/Mastodon/Conversations/Read.php +++ b/src/Module/Api/Mastodon/Conversations/Read.php @@ -38,7 +38,7 @@ class Read extends BaseApi $uid = self::getCurrentUserID(); if (!empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]); @@ -46,7 +46,7 @@ class Read extends BaseApi try { $this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray()); } catch (NotFoundException $e) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } } diff --git a/src/Module/Api/Mastodon/Lists.php b/src/Module/Api/Mastodon/Lists.php index 3e66b9d51e..b9e52f159d 100644 --- a/src/Module/Api/Mastodon/Lists.php +++ b/src/Module/Api/Mastodon/Lists.php @@ -37,15 +37,15 @@ class Lists extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } if (!Circle::exists($this->parameters['id'], $uid)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if (!Circle::remove($this->parameters['id'])) { - $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); + $this->logAndJsonError(500, $this->errorFactory->InternalError()); } $this->jsonExit([]); @@ -61,14 +61,14 @@ class Lists extends BaseApi ], $request); if (empty($request['title'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } Circle::create($uid, $request['title']); $id = Circle::getIdByName($uid, $request['title']); if (!$id) { - $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); + $this->logAndJsonError(500, $this->errorFactory->InternalError()); } $this->jsonExit(DI::mstdnList()->createFromCircleId($id)); @@ -82,7 +82,7 @@ class Lists extends BaseApi ], $request); if (empty($request['title']) || empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } Circle::update($this->parameters['id'], $request['title']); @@ -106,7 +106,7 @@ class Lists extends BaseApi $id = $this->parameters['id']; if (!Circle::exists($id, $uid)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 f72f8cad82..4db6846a27 100644 --- a/src/Module/Api/Mastodon/Lists/Accounts.php +++ b/src/Module/Api/Mastodon/Lists/Accounts.php @@ -43,7 +43,7 @@ class Accounts extends BaseApi ], $request); if (empty($request['account_ids']) || empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } return Circle::removeMembers($this->parameters['id'], $request['account_ids']); @@ -58,7 +58,7 @@ class Accounts extends BaseApi ], $request); if (empty($request['account_ids']) || empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } Circle::addMembers($this->parameters['id'], $request['account_ids']); @@ -73,12 +73,12 @@ class Accounts extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Markers.php b/src/Module/Api/Mastodon/Markers.php index 25b56d72ea..4bd714c117 100644 --- a/src/Module/Api/Mastodon/Markers.php +++ b/src/Module/Api/Mastodon/Markers.php @@ -48,7 +48,7 @@ class Markers extends BaseApi } if (empty($timeline) || empty($last_read_id) || empty($application['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $condition = ['application-id' => $application['id'], 'uid' => $uid, 'timeline' => $timeline]; diff --git a/src/Module/Api/Mastodon/Media.php b/src/Module/Api/Mastodon/Media.php index 738feab7c8..1da6b3006b 100644 --- a/src/Module/Api/Mastodon/Media.php +++ b/src/Module/Api/Mastodon/Media.php @@ -48,12 +48,12 @@ class Media extends BaseApi Logger::info('Photo post', ['request' => $request, 'files' => $_FILES]); if (empty($_FILES['file'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $media = Photo::upload($uid, $_FILES['file'], '', null, null, '', '', $request['description']); if (empty($media)) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } Logger::info('Uploaded photo', ['media' => $media]); @@ -74,17 +74,17 @@ class Media extends BaseApi ], $request); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $photo = Photo::selectFirst(['resource-id'], ['id' => $this->parameters['id'], 'uid' => $uid]); if (empty($photo['resource-id'])) { $media = Post\Media::getById($this->parameters['id']); if (empty($media['uri-id'])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if (!Post::exists(['uri-id' => $media['uri-id'], 'uid' => $uid, 'origin' => true])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } Post\Media::updateById(['description' => $request['description']], $this->parameters['id']); $this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id'])); @@ -104,12 +104,12 @@ class Media extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; if (!Photo::exists(['id' => $id, 'uid' => $uid])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 6557b770b8..b87da7f7b1 100644 --- a/src/Module/Api/Mastodon/Mutes.php +++ b/src/Module/Api/Mastodon/Mutes.php @@ -40,12 +40,12 @@ class Mutes extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Notifications.php b/src/Module/Api/Mastodon/Notifications.php index 6045d24653..b359113dc4 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) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/Notifications/Dismiss.php b/src/Module/Api/Mastodon/Notifications/Dismiss.php index cc89479726..9771f1df6f 100644 --- a/src/Module/Api/Mastodon/Notifications/Dismiss.php +++ b/src/Module/Api/Mastodon/Notifications/Dismiss.php @@ -38,7 +38,7 @@ class Dismiss extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $condition = ['id' => $this->parameters['id']]; diff --git a/src/Module/Api/Mastodon/Polls.php b/src/Module/Api/Mastodon/Polls.php index a5e4fb33a1..51d46c45ba 100644 --- a/src/Module/Api/Mastodon/Polls.php +++ b/src/Module/Api/Mastodon/Polls.php @@ -39,7 +39,7 @@ class Polls extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $this->jsonExit(DI::mstdnPoll()->createFromId($this->parameters['id'], $uid)); diff --git a/src/Module/Api/Mastodon/PushSubscription.php b/src/Module/Api/Mastodon/PushSubscription.php index b91f8e7ba3..5624a1de49 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->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 cedafb8ab7..18b5c31c41 100644 --- a/src/Module/Api/Mastodon/ScheduledStatuses.php +++ b/src/Module/Api/Mastodon/ScheduledStatuses.php @@ -47,11 +47,11 @@ class ScheduledStatuses extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } if (!DBA::exists('delayed-post', ['id' => $this->parameters['id'], 'uid' => $uid])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } Post\Delayed::deleteById($this->parameters['id']); diff --git a/src/Module/Api/Mastodon/Search.php b/src/Module/Api/Mastodon/Search.php index fb222beff2..75dc05e244 100644 --- a/src/Module/Api/Mastodon/Search.php +++ b/src/Module/Api/Mastodon/Search.php @@ -60,7 +60,7 @@ class Search extends BaseApi ], $request); if (empty($request['q'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $limit = min($request['limit'], 40); diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index 5b6f8550aa..dfd81c9d45 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -297,7 +297,7 @@ class Statuses extends BaseApi $item['uri'] = Item::newURI($item['guid']); $id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, DateTimeFormat::utc($request['scheduled_at'])); if (empty($id)) { - $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); + $this->logAndJsonError(500, $this->errorFactory->InternalError()); } $this->jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($id, $uid)->toArray()); } @@ -310,7 +310,7 @@ class Statuses extends BaseApi } } - $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); + $this->logAndJsonError(500, $this->errorFactory->InternalError()); } protected function delete(array $request = []) @@ -319,16 +319,16 @@ class Statuses extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]); if (empty($item['id'])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if (!Item::markForDeletionById($item['id'])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } $this->jsonExit([]); @@ -342,7 +342,7 @@ class Statuses extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), false)); diff --git a/src/Module/Api/Mastodon/Statuses/Bookmark.php b/src/Module/Api/Mastodon/Statuses/Bookmark.php index cdbdcb6e6b..35ebf28d73 100644 --- a/src/Module/Api/Mastodon/Statuses/Bookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Bookmark.php @@ -39,16 +39,16 @@ class Bookmark extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if ($item['gravity'] != Item::GRAVITY_PARENT) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked'))); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked'))); } if ($item['uid'] == 0) { @@ -56,10 +56,10 @@ class Bookmark extends BaseApi if (!empty($stored)) { $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } else { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Card.php b/src/Module/Api/Mastodon/Statuses/Card.php index ea5705186c..ef38f66a82 100644 --- a/src/Module/Api/Mastodon/Statuses/Card.php +++ b/src/Module/Api/Mastodon/Statuses/Card.php @@ -40,7 +40,7 @@ class Card extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php index dbce15058c..6e35d717bf 100644 --- a/src/Module/Api/Mastodon/Statuses/Context.php +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -41,7 +41,7 @@ class Context extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $request = $this->getRequest([ @@ -116,7 +116,7 @@ class Context extends BaseApi } DBA::close($posts); } else { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Favourite.php b/src/Module/Api/Mastodon/Statuses/Favourite.php index 103de86790..04e4c6256c 100644 --- a/src/Module/Api/Mastodon/Statuses/Favourite.php +++ b/src/Module/Api/Mastodon/Statuses/Favourite.php @@ -39,12 +39,12 @@ class Favourite extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 d91eff0b80..96c86dfb1a 100644 --- a/src/Module/Api/Mastodon/Statuses/FavouritedBy.php +++ b/src/Module/Api/Mastodon/Statuses/FavouritedBy.php @@ -41,11 +41,11 @@ class FavouritedBy extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 0931cd733d..fc6b642b48 100644 --- a/src/Module/Api/Mastodon/Statuses/Mute.php +++ b/src/Module/Api/Mastodon/Statuses/Mute.php @@ -39,16 +39,16 @@ class Mute extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if ($item['gravity'] != Item::GRAVITY_PARENT) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be muted'))); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be muted'))); } Post\ThreadUser::setIgnored($item['uri-id'], $uid, true); diff --git a/src/Module/Api/Mastodon/Statuses/Pin.php b/src/Module/Api/Mastodon/Statuses/Pin.php index fbd2f00cee..b5c8f5c6e0 100644 --- a/src/Module/Api/Mastodon/Statuses/Pin.php +++ b/src/Module/Api/Mastodon/Statuses/Pin.php @@ -38,12 +38,12 @@ class Pin extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 54ada1d1f9..cf35286b2c 100644 --- a/src/Module/Api/Mastodon/Statuses/Reblog.php +++ b/src/Module/Api/Mastodon/Statuses/Reblog.php @@ -42,18 +42,18 @@ class Reblog extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if ($item['network'] == Protocol::DIASPORA) { Diaspora::performReshare($this->parameters['id'], $uid); } elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) { - $this->logErrorAndJsonExit( + $this->logAndJsonError( 422, $this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network']))) ); diff --git a/src/Module/Api/Mastodon/Statuses/RebloggedBy.php b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php index eab40c665e..0c8376fd07 100644 --- a/src/Module/Api/Mastodon/Statuses/RebloggedBy.php +++ b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php @@ -41,11 +41,11 @@ class RebloggedBy extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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/Source.php b/src/Module/Api/Mastodon/Statuses/Source.php index 1e72f33a02..8810058d62 100644 --- a/src/Module/Api/Mastodon/Statuses/Source.php +++ b/src/Module/Api/Mastodon/Statuses/Source.php @@ -41,7 +41,7 @@ class Source extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $id = $this->parameters['id']; diff --git a/src/Module/Api/Mastodon/Statuses/Unbookmark.php b/src/Module/Api/Mastodon/Statuses/Unbookmark.php index c64a6c8a77..594cde4223 100644 --- a/src/Module/Api/Mastodon/Statuses/Unbookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Unbookmark.php @@ -39,16 +39,16 @@ class Unbookmark extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if ($item['gravity'] != Item::GRAVITY_PARENT) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked'))); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked'))); } if ($item['uid'] == 0) { @@ -56,10 +56,10 @@ class Unbookmark extends BaseApi if (!empty($stored)) { $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } else { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Unfavourite.php b/src/Module/Api/Mastodon/Statuses/Unfavourite.php index 78e9fb350f..631e18dda7 100644 --- a/src/Module/Api/Mastodon/Statuses/Unfavourite.php +++ b/src/Module/Api/Mastodon/Statuses/Unfavourite.php @@ -39,12 +39,12 @@ class Unfavourite extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 e54380dbe5..9fb05e8f69 100644 --- a/src/Module/Api/Mastodon/Statuses/Unmute.php +++ b/src/Module/Api/Mastodon/Statuses/Unmute.php @@ -39,16 +39,16 @@ class Unmute extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if ($item['gravity'] != Item::GRAVITY_PARENT) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unmuted'))); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unmuted'))); } Post\ThreadUser::setIgnored($item['uri-id'], $uid, false); diff --git a/src/Module/Api/Mastodon/Statuses/Unpin.php b/src/Module/Api/Mastodon/Statuses/Unpin.php index f04ff5306e..626e18d75c 100644 --- a/src/Module/Api/Mastodon/Statuses/Unpin.php +++ b/src/Module/Api/Mastodon/Statuses/Unpin.php @@ -38,12 +38,12 @@ class Unpin extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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 50931cecd7..2036bb1fb1 100644 --- a/src/Module/Api/Mastodon/Statuses/Unreblog.php +++ b/src/Module/Api/Mastodon/Statuses/Unreblog.php @@ -41,25 +41,25 @@ class Unreblog extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(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'])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if (!Item::markForDeletionById($item['id'])) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } } elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) { - $this->logErrorAndJsonExit( + $this->logAndJsonError( 422, $this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network']))) ); diff --git a/src/Module/Api/Mastodon/Tags.php b/src/Module/Api/Mastodon/Tags.php index d61ee88acf..00cbac0d91 100644 --- a/src/Module/Api/Mastodon/Tags.php +++ b/src/Module/Api/Mastodon/Tags.php @@ -40,7 +40,7 @@ class Tags extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['hashtag'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $tag = ltrim($this->parameters['hashtag'], '#'); diff --git a/src/Module/Api/Mastodon/Tags/Follow.php b/src/Module/Api/Mastodon/Tags/Follow.php index 03844a7ddc..0fe6307ebc 100644 --- a/src/Module/Api/Mastodon/Tags/Follow.php +++ b/src/Module/Api/Mastodon/Tags/Follow.php @@ -37,7 +37,7 @@ class Follow extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['hashtag'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $fields = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')]; diff --git a/src/Module/Api/Mastodon/Tags/Unfollow.php b/src/Module/Api/Mastodon/Tags/Unfollow.php index 07b93d95a2..31e2ade4ea 100644 --- a/src/Module/Api/Mastodon/Tags/Unfollow.php +++ b/src/Module/Api/Mastodon/Tags/Unfollow.php @@ -37,7 +37,7 @@ class Unfollow extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['hashtag'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $term = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')]; diff --git a/src/Module/Api/Mastodon/Timelines/Direct.php b/src/Module/Api/Mastodon/Timelines/Direct.php index 730b639104..356a4fa949 100644 --- a/src/Module/Api/Mastodon/Timelines/Direct.php +++ b/src/Module/Api/Mastodon/Timelines/Direct.php @@ -83,7 +83,7 @@ class Direct extends BaseApi $statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']); } } catch (NotFoundException $e) { - $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound()); + $this->logAndJsonError(404, $this->errorFactory->RecordNotFound()); } if (!empty($request['min_id'])) { diff --git a/src/Module/Api/Mastodon/Timelines/ListTimeline.php b/src/Module/Api/Mastodon/Timelines/ListTimeline.php index baed01e0ec..4331fc321c 100644 --- a/src/Module/Api/Mastodon/Timelines/ListTimeline.php +++ b/src/Module/Api/Mastodon/Timelines/ListTimeline.php @@ -45,7 +45,7 @@ class ListTimeline extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['id'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } $request = $this->getRequest([ diff --git a/src/Module/Api/Mastodon/Timelines/Tag.php b/src/Module/Api/Mastodon/Timelines/Tag.php index 60bdab8373..e08453327c 100644 --- a/src/Module/Api/Mastodon/Timelines/Tag.php +++ b/src/Module/Api/Mastodon/Timelines/Tag.php @@ -45,7 +45,7 @@ class Tag extends BaseApi $uid = self::getCurrentUserID(); if (empty($this->parameters['hashtag'])) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } /** diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index b2d729f286..7d21d7a8d4 100644 --- a/src/Module/BaseApi.php +++ b/src/Module/BaseApi.php @@ -424,17 +424,17 @@ class BaseApi extends BaseModule if (empty($token)) { $this->logger->notice('Empty application token'); - $this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden()); + $this->logAndJsonError(403, $this->errorFactory->Forbidden()); } if (!isset($token[$scope])) { $this->logger->warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]); - $this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden()); + $this->logAndJsonError(403, $this->errorFactory->Forbidden()); } if (empty($token[$scope])) { $this->logger->warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]); - $this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden()); + $this->logAndJsonError(403, $this->errorFactory->Forbidden()); } } @@ -526,7 +526,7 @@ class BaseApi extends BaseModule * @return void * @throws HTTPException\InternalServerErrorException */ - protected function logErrorAndJsonExit(int $errorno, Error $error) + protected function logAndJsonError(int $errorno, Error $error) { $this->logger->info('API Error', ['no' => $errorno, 'error' => $error->toArray(), 'method' => $this->args->getMethod(), 'command' => $this->args->getQueryString(), 'user-agent' => $this->server['HTTP_USER_AGENT'] ?? '']); $this->jsonError(403, $error->toArray()); diff --git a/src/Module/OAuth/Authorize.php b/src/Module/OAuth/Authorize.php index e9ef07c62f..31db02b017 100644 --- a/src/Module/OAuth/Authorize.php +++ b/src/Module/OAuth/Authorize.php @@ -51,17 +51,17 @@ class Authorize extends BaseApi if ($request['response_type'] != 'code') { Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]); - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing response type'))); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing response type'))); } if (empty($request['client_id']) || empty($request['redirect_uri'])) { Logger::warning('Incomplete request data', ['request' => $_REQUEST]); - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data'))); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data'))); } $application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']); if (empty($application)) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } // @todo Compare the application scope and requested scope @@ -87,7 +87,7 @@ class Authorize extends BaseApi $token = OAuth::createTokenForUser($application, $uid, $request['scope']); if (!$token) { - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity()); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity()); } if ($application['redirect_uri'] != 'urn:ietf:wg:oauth:2.0:oob') { diff --git a/src/Module/OAuth/Revoke.php b/src/Module/OAuth/Revoke.php index 9791144348..a20482b221 100644 --- a/src/Module/OAuth/Revoke.php +++ b/src/Module/OAuth/Revoke.php @@ -51,7 +51,7 @@ class Revoke extends BaseApi $token = DBA::selectFirst('application-view', ['id'], $condition); if (empty($token['id'])) { $this->logger->notice('Token not found', $condition); - $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized()); + $this->logAndJsonError(401, $this->errorFactory->Unauthorized()); } DBA::delete('application-token', ['application-id' => $token['id']]); diff --git a/src/Module/OAuth/Token.php b/src/Module/OAuth/Token.php index 0186f28519..7e22a88dab 100644 --- a/src/Module/OAuth/Token.php +++ b/src/Module/OAuth/Token.php @@ -75,12 +75,12 @@ class Token extends BaseApi if (empty($request['client_id']) || empty($request['client_secret'])) { $this->logger->warning('Incomplete request data', ['request' => $request]); - $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Incomplete request data')));; + $this->logAndJsonError(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Incomplete request data')));; } $application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']); if (empty($application)) { - $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client'))); + $this->logAndJsonError(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client'))); } if ($request['grant_type'] == 'client_credentials') { @@ -99,13 +99,13 @@ class Token extends BaseApi $token = DBA::selectFirst('application-view', ['access_token', 'created_at', 'uid'], $condition); if (!DBA::isResult($token)) { $this->logger->notice('Token not found or outdated', $condition); - $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized()); + $this->logAndJsonError(401, $this->errorFactory->Unauthorized()); } $owner = User::getOwnerDataById($token['uid']); $me = $owner['url']; } else { Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]); - $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing grant type'))); + $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing grant type'))); } $object = new \Friendica\Object\Api\Mastodon\Token($token['access_token'], 'Bearer', $application['scopes'], $token['created_at'], $me);