From 0a91484fa037c7c2e3fe5ad2e31abadd4494a106 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Oct 2023 09:32:25 -0400 Subject: [PATCH] Move jsonError out of Factory\Api\Mastodon\Error->InternalError --- src/Factory/Api/Mastodon/Error.php | 7 ++----- src/Module/Api/Mastodon/Apps.php | 2 +- src/Module/Api/Mastodon/Lists.php | 4 ++-- src/Module/Api/Mastodon/Statuses.php | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Factory/Api/Mastodon/Error.php b/src/Factory/Api/Mastodon/Error.php index 7d8e02676..4f7159b7e 100644 --- a/src/Factory/Api/Mastodon/Error.php +++ b/src/Factory/Api/Mastodon/Error.php @@ -77,13 +77,10 @@ class Error extends BaseFactory return new \Friendica\Object\Api\Mastodon\Error($error, $error_description); } - public function InternalError(string $error = '') + public function InternalError(string $error = ''): \Friendica\Object\Api\Mastodon\Error { $error = $error ?: $this->l10n->t('Internal Server Error'); $error_description = ''; - $errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); - - $this->logError(500, $error); - $this->jsonError(500, $errorObj->toArray()); + return new \Friendica\Object\Api\Mastodon\Error($error, $error_description); } } diff --git a/src/Module/Api/Mastodon/Apps.php b/src/Module/Api/Mastodon/Apps.php index 9d6729216..5ebe3e2ab 100644 --- a/src/Module/Api/Mastodon/Apps.php +++ b/src/Module/Api/Mastodon/Apps.php @@ -92,7 +92,7 @@ class Apps extends BaseApi } if (!DBA::insert('application', $fields)) { - DI::mstdnError()->InternalError(); + $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); } $this->jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray()); diff --git a/src/Module/Api/Mastodon/Lists.php b/src/Module/Api/Mastodon/Lists.php index beb1a3b9a..3e66b9d51 100644 --- a/src/Module/Api/Mastodon/Lists.php +++ b/src/Module/Api/Mastodon/Lists.php @@ -45,7 +45,7 @@ class Lists extends BaseApi } if (!Circle::remove($this->parameters['id'])) { - DI::mstdnError()->InternalError(); + $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); } $this->jsonExit([]); @@ -68,7 +68,7 @@ class Lists extends BaseApi $id = Circle::getIdByName($uid, $request['title']); if (!$id) { - DI::mstdnError()->InternalError(); + $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); } $this->jsonExit(DI::mstdnList()->createFromCircleId($id)); diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index def4d51f6..5b6f8550a 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)) { - DI::mstdnError()->InternalError(); + $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); } $this->jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($id, $uid)->toArray()); } @@ -310,7 +310,7 @@ class Statuses extends BaseApi } } - DI::mstdnError()->InternalError(); + $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError()); } protected function delete(array $request = [])