From 696c56b6be660f755194ee6c65706006ed8e5e3f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Oct 2023 09:31:02 -0400 Subject: [PATCH] Move jsonError out of Factory\Api\Mastodon\Error->Forbidden --- src/Factory/Api/Mastodon/Error.php | 7 ++----- src/Module/BaseApi.php | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Factory/Api/Mastodon/Error.php b/src/Factory/Api/Mastodon/Error.php index 6614100642..7d8e026767 100644 --- a/src/Factory/Api/Mastodon/Error.php +++ b/src/Factory/Api/Mastodon/Error.php @@ -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 = '') diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index 95eb8f0424..b2d729f286 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'); - 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()); } }