]> git.mxchange.org Git - friendica.git/commitdiff
Move jsonError out of Factory\Api\Mastodon\Error->UnprocessableEntity
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 11 Oct 2023 13:20:49 +0000 (09:20 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 11 Oct 2023 13:44:03 +0000 (09:44 -0400)
52 files changed:
src/Factory/Api/Mastodon/Error.php
src/Module/Api/Friendica/Statuses/Dislike.php
src/Module/Api/Friendica/Statuses/DislikedBy.php
src/Module/Api/Friendica/Statuses/Undislike.php
src/Module/Api/Mastodon/Accounts.php
src/Module/Api/Mastodon/Accounts/Block.php
src/Module/Api/Mastodon/Accounts/Follow.php
src/Module/Api/Mastodon/Accounts/Followers.php
src/Module/Api/Mastodon/Accounts/Following.php
src/Module/Api/Mastodon/Accounts/Lists.php
src/Module/Api/Mastodon/Accounts/Mute.php
src/Module/Api/Mastodon/Accounts/Note.php
src/Module/Api/Mastodon/Accounts/Relationships.php
src/Module/Api/Mastodon/Accounts/Statuses.php
src/Module/Api/Mastodon/Accounts/Unblock.php
src/Module/Api/Mastodon/Accounts/Unfollow.php
src/Module/Api/Mastodon/Accounts/Unmute.php
src/Module/Api/Mastodon/Apps.php
src/Module/Api/Mastodon/Conversations.php
src/Module/Api/Mastodon/Conversations/Read.php
src/Module/Api/Mastodon/Lists.php
src/Module/Api/Mastodon/Lists/Accounts.php
src/Module/Api/Mastodon/Markers.php
src/Module/Api/Mastodon/Media.php
src/Module/Api/Mastodon/Mutes.php
src/Module/Api/Mastodon/Notifications/Dismiss.php
src/Module/Api/Mastodon/Polls.php
src/Module/Api/Mastodon/ScheduledStatuses.php
src/Module/Api/Mastodon/Search.php
src/Module/Api/Mastodon/Statuses.php
src/Module/Api/Mastodon/Statuses/Bookmark.php
src/Module/Api/Mastodon/Statuses/Card.php
src/Module/Api/Mastodon/Statuses/Context.php
src/Module/Api/Mastodon/Statuses/Favourite.php
src/Module/Api/Mastodon/Statuses/FavouritedBy.php
src/Module/Api/Mastodon/Statuses/Mute.php
src/Module/Api/Mastodon/Statuses/Pin.php
src/Module/Api/Mastodon/Statuses/Reblog.php
src/Module/Api/Mastodon/Statuses/RebloggedBy.php
src/Module/Api/Mastodon/Statuses/Source.php
src/Module/Api/Mastodon/Statuses/Unbookmark.php
src/Module/Api/Mastodon/Statuses/Unfavourite.php
src/Module/Api/Mastodon/Statuses/Unmute.php
src/Module/Api/Mastodon/Statuses/Unpin.php
src/Module/Api/Mastodon/Statuses/Unreblog.php
src/Module/Api/Mastodon/Tags.php
src/Module/Api/Mastodon/Tags/Follow.php
src/Module/Api/Mastodon/Tags/Unfollow.php
src/Module/Api/Mastodon/Timelines/ListTimeline.php
src/Module/Api/Mastodon/Timelines/Tag.php
src/Module/OAuth/Authorize.php
src/Module/OAuth/Token.php

index dec56ba90f38ffe5a891ea3c00ed150638720f18..1dad4d9c8e4f34090a87653287947ed43dfea28f 100644 (file)
@@ -57,14 +57,11 @@ class Error extends BaseFactory
                return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
        }
 
-       public function UnprocessableEntity(string $error = '')
+       public function UnprocessableEntity(string $error = ''): \Friendica\Object\Api\Mastodon\Error
        {
                $error             = $error ?: $this->l10n->t('Unprocessable Entity');
                $error_description = '';
-               $errorObj          = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
-
-               $this->logError(422, $error);
-               $this->jsonError(422, $errorObj->toArray());
+               return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
        }
 
        public function Unauthorized(string $error = '', string $error_description = '')
index a0dcd7077df0146e0b4180a9e845098b9e91d2c8..99c8eb857a57985c24bcf70879b7817836406f87 100644 (file)
@@ -39,7 +39,7 @@ class Dislike extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
index fcae9990ce20e2a88fba6ddcbdbfd0846d328e5f..3c13120873e6697b6202742b91368d6b84dc69fa 100644 (file)
@@ -41,7 +41,7 @@ class DislikedBy extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $id = $this->parameters['id'];
index f304fb9db928fa65374d2c6e3d9638725d1ae481..5387f1b10578871c0d94e54b5c64a95ad08a21d9 100644 (file)
@@ -39,7 +39,7 @@ class Undislike extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
index 4ebd0d4bd3d52021aaf3a5f48eb01d91ea531f87..6b88b84ef3fac571fc365743abdfbd1e8888cda8 100644 (file)
@@ -40,7 +40,7 @@ class Accounts extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id']) && empty($this->parameters['name'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                if (!empty($this->parameters['id'])) {
index 1ddafda5696e9fa8f11b5f3ed87c999869e6ea66..1582f3299c18d5a21cad7ccb23320a928c5f7af7 100644 (file)
@@ -38,7 +38,7 @@ class Block extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                Contact\User::setBlocked($this->parameters['id'], $uid, true);
index a666f2f91ded47050c0f6c0db4af3a8d42a13cc4..272b989ee4e50e070815bda3cad4349696b87e8e 100644 (file)
@@ -37,7 +37,7 @@ class Follow extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $request = $this->getRequest([
index 22b99ee4d63cfe6e1a3fa647fa3775fc2d75894b..19f2a438838041540f6c833854255f87d754502b 100644 (file)
@@ -41,7 +41,7 @@ class Followers extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $id = $this->parameters['id'];
index 0fde1404e32fd18f9e2c876dba31bd1fc5e607ac..061e22663d81ab01a81561c7fc68d83d9fdcb11c 100644 (file)
@@ -41,7 +41,7 @@ class Following extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $id = $this->parameters['id'];
index f0187a2861891a5b625c33999b7e66443f1c23d9..8fdcade664213803406c123b7052d3d58bd43be1 100644 (file)
@@ -41,7 +41,7 @@ class Lists extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $id = $this->parameters['id'];
index 4169cb90fa4fd3296f5b924effc65ee04a3270a7..ea8d0ce30954156565169c5fb6ccf82a310ddaf5 100644 (file)
@@ -37,7 +37,7 @@ class Mute extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                Contact\User::setIgnored($this->parameters['id'], $uid, true);
index 52c76ab6934e79700785684a8fb0e41ff6759cb6..72a7e0838d35fb79025204b3e80419ce59920baf 100644 (file)
@@ -38,7 +38,7 @@ class Note extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $request = $this->getRequest([
index 4ae5b0669098d445729956c900773d57d6ef327e..f757151724d419d294ec77e36b01404767673418 100644 (file)
@@ -44,7 +44,7 @@ class Relationships extends BaseApi
                ], $request);
 
                if (empty($request['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                if (!is_array($request['id'])) {
index 599a2eff8aefc707e0cd9c862670d93e3e83643f..fd8fbcdab1ccb00483d9adf39f669392f2d69a96 100644 (file)
@@ -47,7 +47,7 @@ class Statuses extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $id = $this->parameters['id'];
index 8d8fb3e39ce22e6beaef8591b953e9a8c59806cf..f2e2f2e411ba10ca74340daa5014144a1cd22bc3 100644 (file)
@@ -37,7 +37,7 @@ class Unblock extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                Contact\User::setBlocked($this->parameters['id'], $uid, false);
index cfe3b3cb1eccb15475a81392cfffc0b7fff18770..6a3c68cb3263c151c58cc946a45c7d57c10fda96 100644 (file)
@@ -37,7 +37,7 @@ class Unfollow extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
index 7708e1472b7ff787fd20171a81d9e52253ed4ce7..651233daed361b95c6f28d30af39342fc1039294 100644 (file)
@@ -37,7 +37,7 @@ class Unmute extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                Contact\User::setIgnored($this->parameters['id'], $uid, false);
index d51a8e7b0a9b9e09af1db5d9d8399de1f8e716ac..9d6729216c563bb57e60d42adbe4e35a8b0ffade 100644 (file)
@@ -70,7 +70,7 @@ class Apps extends BaseApi
                }
 
                if (empty($request['client_name']) || empty($request['redirect_uris'])) {
-                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Missing parameters'));
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters')));
                }
 
                $client_id     = bin2hex(random_bytes(32));
index c45144c98d31f2f66766befdd54c2b121c3dad53..532db4bcda95f0c2784b5c47cfc445c255193064 100644 (file)
@@ -38,7 +38,7 @@ class Conversations extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (!empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                DBA::delete('conv', ['id' => $this->parameters['id'], 'uid' => $uid]);
index 86a5090e37a73ee2e58f1b7a67186bc739a0532c..2e876fcb5d3abaf1c05c06ff8ff80af968ea9b02 100644 (file)
@@ -38,7 +38,7 @@ class Read extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (!empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]);
index 9d9e6955b1e6851b574ebbc96e19e944abe24f6b..beb1a3b9a62455fd552f6a2022726c8d6eaa145d 100644 (file)
@@ -37,7 +37,7 @@ class Lists extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                if (!Circle::exists($this->parameters['id'], $uid)) {
@@ -61,7 +61,7 @@ class Lists extends BaseApi
                ], $request);
 
                if (empty($request['title'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                Circle::create($uid, $request['title']);
@@ -82,7 +82,7 @@ class Lists extends BaseApi
                ], $request);
 
                if (empty($request['title']) || empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                Circle::update($this->parameters['id'], $request['title']);
index ffa63caf44adc3f5737658722e24c9bff0893e80..f72f8cad82ebf7f73c646d9cfd630df1387e8321 100644 (file)
@@ -43,7 +43,7 @@ class Accounts extends BaseApi
                ], $request);
 
                if (empty($request['account_ids']) || empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(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'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                Circle::addMembers($this->parameters['id'], $request['account_ids']);
@@ -73,7 +73,7 @@ class Accounts extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $id = $this->parameters['id'];
index eb19acf8ebda235a91852db15ced58d6d2d8003a..25b56d72ea0a5e6d6c6857447db26858f96d238a 100644 (file)
@@ -48,7 +48,7 @@ class Markers extends BaseApi
                }
 
                if (empty($timeline) || empty($last_read_id) || empty($application['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $condition = ['application-id' => $application['id'], 'uid' => $uid, 'timeline' => $timeline];
index 91c88ee181cbab0eb743e580a425cbe5b1b8b664..738feab7c8fa011ac4c6256d714cda0547799598 100644 (file)
@@ -48,12 +48,12 @@ class Media extends BaseApi
                Logger::info('Photo post', ['request' => $request, 'files' => $_FILES]);
 
                if (empty($_FILES['file'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $media = Photo::upload($uid, $_FILES['file'], '', null, null, '', '', $request['description']);
                if (empty($media)) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                Logger::info('Uploaded photo', ['media' => $media]);
@@ -74,7 +74,7 @@ class Media extends BaseApi
                ], $request);
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $photo = Photo::selectFirst(['resource-id'], ['id' => $this->parameters['id'], 'uid' => $uid]);
@@ -104,7 +104,7 @@ class Media extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $id = $this->parameters['id'];
index 71b1949f5736537b5e54baced837dbd67983d75e..6557b770b8470e87c10e1d309d522398ed445b35 100644 (file)
@@ -40,7 +40,7 @@ class Mutes extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $id = $this->parameters['id'];
index 50d1be27b5de6460c4dbc812e9e23b7bb1c70b01..cc8947972684548570b7c5d2d0282547cfc07dea 100644 (file)
@@ -38,7 +38,7 @@ class Dismiss extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $condition = ['id' => $this->parameters['id']];
index c43bdf510fcf31002e214d92c8d87e77333d99e3..a5e4fb33a1f721e40881c1cb087773fe47038d6c 100644 (file)
@@ -39,7 +39,7 @@ class Polls extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $this->jsonExit(DI::mstdnPoll()->createFromId($this->parameters['id'], $uid));
index f136c2708f01e2155d42be09d182a37c90ad9055..cedafb8ab7f2a9689db7adaa3632d081fbbaccea 100644 (file)
@@ -47,7 +47,7 @@ class ScheduledStatuses extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                if (!DBA::exists('delayed-post', ['id' => $this->parameters['id'], 'uid' => $uid])) {
index ec4527f00deddea3fd979fb55caf14f033bb699d..fb222beff27e63c9aabc01950fed5aae31ac496b 100644 (file)
@@ -60,7 +60,7 @@ class Search extends BaseApi
                ], $request);
 
                if (empty($request['q'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $limit = min($request['limit'], 40);
index 0940befbada325efda6fbb6f29850a9ed8ccb188..def4d51f631d03ab0324d0bf879b7e5d16b6f05b 100644 (file)
@@ -319,7 +319,7 @@ class Statuses extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]);
@@ -342,7 +342,7 @@ class Statuses extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), false));
index 1ba0d6e04024f5fc5af17a717b348b5c84e6ac68..cdbdcb6e6baf8761997d443ecf40568c54b6baa7 100644 (file)
@@ -39,7 +39,7 @@ class Bookmark extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
@@ -48,7 +48,7 @@ class Bookmark extends BaseApi
                }
 
                if ($item['gravity'] != Item::GRAVITY_PARENT) {
-                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be bookmarked'));
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked')));
                }
 
                if ($item['uid'] == 0) {
index 193bb7b0cd33ec02aa0405ed5ac5612461015646..ea5705186cec1acc9d4856293da1a20fbc40df92 100644 (file)
@@ -40,7 +40,7 @@ class Card extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
index c171c0ccae08de3c86d550a1d80d27b7267a39b9..dbce15058cad1f1f415a6788c79bea51650d2ba5 100644 (file)
@@ -41,7 +41,7 @@ class Context extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $request = $this->getRequest([
index 384abc3d82b3f4d3f6595a2e9101497359a2577a..103de86790da90af046c828cdf29414cda536971 100644 (file)
@@ -39,7 +39,7 @@ class Favourite extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
index bce95610a928a699f1ce99a02061ec43fef21194..d91eff0b803e1fb592eb724f9ce6743573d939f4 100644 (file)
@@ -41,7 +41,7 @@ class FavouritedBy extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
index 68491c8b707d4403339ad65c21618f3740e81058..0931cd733d8f4dd70b3d267b98e6725fb5e5f74e 100644 (file)
@@ -39,7 +39,7 @@ class Mute extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
@@ -48,7 +48,7 @@ class Mute extends BaseApi
                }
 
                if ($item['gravity'] != Item::GRAVITY_PARENT) {
-                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be muted'));
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be muted')));
                }
 
                Post\ThreadUser::setIgnored($item['uri-id'], $uid, true);
index 99f097740fe1a2ab715df2458f9bfd7d9f92d43e..fbd2f00ceefa51fcb584017bce955e6700747764 100644 (file)
@@ -38,7 +38,7 @@ class Pin extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
index 3e37a94a7d51868b010abf52b2ab3130273c7154..54ada1d1f91b89387a2a7034c9140ce646f7b97c 100644 (file)
@@ -42,7 +42,7 @@ class Reblog extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
@@ -53,7 +53,10 @@ class Reblog extends BaseApi
                if ($item['network'] == Protocol::DIASPORA) {
                        Diaspora::performReshare($this->parameters['id'], $uid);
                } elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
-                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])));
+                       $this->logErrorAndJsonExit(
+                               422,
+                               $this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])))
+                       );
                } else {
                        Item::performActivity($item['id'], 'announce', $uid);
                }
index 9c508e42a93aced81b21d1df105200d5cffa8e0b..eab40c665e20ac4a572948e4cf35680da60ae629 100644 (file)
@@ -41,7 +41,7 @@ class RebloggedBy extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
index 408df3aad584fd019ac6fde70500111b5e6992bd..1e72f33a02516a6a8ee5284198d32ed9ffe734df 100644 (file)
@@ -41,7 +41,7 @@ class Source extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $id = $this->parameters['id'];
index 4eccc97b2e1f9c8ddd1ce84501ab00a0fcf0c48b..c64a6c8a775dc18474898e552df438d4354696ee 100644 (file)
@@ -39,7 +39,7 @@ class Unbookmark extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
@@ -48,7 +48,7 @@ class Unbookmark extends BaseApi
                }
 
                if ($item['gravity'] != Item::GRAVITY_PARENT) {
-                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unbookmarked'));
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked')));
                }
 
                if ($item['uid'] == 0) {
index ada587b2fefefa72653e02b44c79c28d20939e41..78e9fb350f2e90aa75d84a2f752d752f0ffe13b5 100644 (file)
@@ -39,7 +39,7 @@ class Unfavourite extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
index 511ae15407a29e208b9d097b30c21703638fda5c..e54380dbe59754a2f51967daa907534b72c688fd 100644 (file)
@@ -39,7 +39,7 @@ class Unmute extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
@@ -48,7 +48,7 @@ class Unmute extends BaseApi
                }
 
                if ($item['gravity'] != Item::GRAVITY_PARENT) {
-                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unmuted'));
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unmuted')));
                }
 
                Post\ThreadUser::setIgnored($item['uri-id'], $uid, false);
index c11f89f6e09c0b886c62f61f800e17cf1e162b30..f04ff5306e1ac9e29792fa360fb44f9859c7f6ca 100644 (file)
@@ -38,7 +38,7 @@ class Unpin extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
index c99011ae43736fc6cb79d81d9d8d017284b31974..50931cecd7bf8ac7cca038ee0821be7f001636a6 100644 (file)
@@ -41,7 +41,7 @@ class Unreblog extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
@@ -59,7 +59,10 @@ class Unreblog extends BaseApi
                                $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'])));
+                       $this->logErrorAndJsonExit(
+                               422,
+                               $this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])))
+                       );
                } else {
                        Item::performActivity($item['id'], 'unannounce', $uid);
                }
index d636dd9126ee20c9481cf502d7265f85b917f317..d61ee88acf9c1b917ca038a2e0965150ce8ed8aa 100644 (file)
@@ -40,7 +40,7 @@ class Tags extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['hashtag'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $tag       = ltrim($this->parameters['hashtag'], '#');
index a450b2248e586b0b49e16f13a921010687f16b03..03844a7ddccb9e751e2c0e2e31a1244c73807ee3 100644 (file)
@@ -37,7 +37,7 @@ class Follow extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['hashtag'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $fields = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
index b4a1a7e73d0825e2b2eea09ed212b7a281821123..07b93d95a2dedc8c2cf3a4feb752f5445f556235 100644 (file)
@@ -37,7 +37,7 @@ class Unfollow extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['hashtag'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $term = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
index 2834b63fc36d080fadd922cbea32177eb11793af..baed01e0ec5de318b5014928bb04274032bc03ce 100644 (file)
@@ -45,7 +45,7 @@ class ListTimeline extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['id'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                $request = $this->getRequest([
index 9bbafd587e7a5882c0ee6dc9d5b4d78323f635d3..60bdab837349b6934b32e28d18a877b91cbface3 100644 (file)
@@ -45,7 +45,7 @@ class Tag extends BaseApi
                $uid = self::getCurrentUserID();
 
                if (empty($this->parameters['hashtag'])) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                /**
index ea91de5a045d70f8fd8b4d9be74bb51edde0715b..e9ef07c62fbc0ceff41927ad09c6a1a7e2c6658c 100644 (file)
@@ -51,17 +51,17 @@ class Authorize extends BaseApi
 
                if ($request['response_type'] != 'code') {
                        Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]);
-                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing response type'));
+                       $this->logErrorAndJsonExit(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]);
-                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Incomplete request data'));
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data')));
                }
 
                $application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
                if (empty($application)) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(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) {
-                       DI::mstdnError()->UnprocessableEntity();
+                       $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
                }
 
                if ($application['redirect_uri'] != 'urn:ietf:wg:oauth:2.0:oob') {
index 61a7f22889e5bd5ed09f2afa4e252008a2da8ade..ab9cd3ec26f85d34efebd5c2552ad77964f3e8e0 100644 (file)
@@ -105,7 +105,7 @@ class Token extends BaseApi
                        $me = $owner['url'];
                } else {
                        Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]);
-                       DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing grant type'));
+                       $this->logErrorAndJsonExit(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);