]> git.mxchange.org Git - friendica.git/commitdiff
Move jsonError out of Factory\Api\Mastodon\Error->Forbidden
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 11 Oct 2023 13:31:02 +0000 (09:31 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 11 Oct 2023 13:44:03 +0000 (09:44 -0400)
src/Factory/Api/Mastodon/Error.php
src/Module/BaseApi.php

index 66141006429dcaac0ddd10a76792b20bfa4752fb..7d8e026767d2e286ebdd16db3ca44a839de5bfa8 100644 (file)
@@ -70,14 +70,11 @@ class Error extends BaseFactory
                return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
        }
 
-       public function Forbidden(string $error = '')
+       public function Forbidden(string $error = ''): \Friendica\Object\Api\Mastodon\Error
        {
                $error             = $error ?: $this->l10n->t('Token is not authorized with a valid user or is missing a required scope');
                $error_description = '';
-               $errorObj          = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
-
-               $this->logError(403, $error);
-               $this->jsonError(403, $errorObj->toArray());
+               return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
        }
 
        public function InternalError(string $error = '')
index 95eb8f04249d005eef54a5162b1d4e8f16c51eec..b2d729f286d5c84e786c5c82b0219d18596b6f5d 100644 (file)
@@ -424,17 +424,17 @@ class BaseApi extends BaseModule
 
                if (empty($token)) {
                        $this->logger->notice('Empty application token');
-                       DI::mstdnError()->Forbidden();
+                       $this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
                }
 
                if (!isset($token[$scope])) {
                        $this->logger->warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]);
-                       DI::mstdnError()->Forbidden();
+                       $this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
                }
 
                if (empty($token[$scope])) {
                        $this->logger->warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]);
-                       DI::mstdnError()->Forbidden();
+                       $this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
                }
        }