From d1e109d9beda95fa0e043f3e4e9f19cfaa4ad42f Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 May 2021 03:05:22 +0000 Subject: [PATCH] Improved error handling --- src/Factory/Api/Mastodon/Error.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Factory/Api/Mastodon/Error.php b/src/Factory/Api/Mastodon/Error.php index 2c3662288..086cceef9 100644 --- a/src/Factory/Api/Mastodon/Error.php +++ b/src/Factory/Api/Mastodon/Error.php @@ -35,4 +35,31 @@ class Error extends BaseFactory System::jsonError(404, $errorobj->toArray()); } + + public function UnprocessableEntity(string $error = '') + { + $error = $error ?: DI::l10n()->t('Unprocessable Entity'); + $error_description = ''; + $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description); + + System::jsonError(422, $errorobj->toArray()); + } + + public function Unauthorized(string $error = '') + { + $error = $error ?: DI::l10n()->t('Unauthorized'); + $error_description = ''; + $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description); + + System::jsonError(401, $errorobj->toArray()); + } + + public function InternalError(string $error = '') + { + $error = $error ?: DI::l10n()->t('Internal Server Error'); + $error_description = ''; + $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description); + + System::jsonError(500, $errorobj->toArray()); + } }