]> git.mxchange.org Git - friendica.git/blob - src/Factory/Api/Mastodon/Error.php
Removed unused parameter
[friendica.git] / src / Factory / Api / Mastodon / Error.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Factory\Api\Mastodon;
23
24 use Friendica\BaseFactory;
25 use Friendica\Core\Logger;
26 use Friendica\Core\System;
27 use Friendica\DI;
28
29 class Error extends BaseFactory
30 {
31         private function logError(int $errorno, string $error)
32         {
33                 Logger::info('API Error', ['no' => $errorno, 'error' => $error, 'method' => $_SERVER['REQUEST_METHOD'] ?? '', 'command' => DI::args()->getQueryString(), 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
34         }
35
36         public function RecordNotFound()
37         {
38                 $error = DI::l10n()->t('Record not found');
39                 $error_description = '';
40                 $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
41
42                 $this->logError(404, $error);
43                 System::jsonError(404, $errorobj->toArray());
44         }
45
46         public function UnprocessableEntity(string $error = '')
47         {
48                 $error = $error ?: DI::l10n()->t('Unprocessable Entity');
49                 $error_description = '';
50                 $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
51
52                 $this->logError(422, $error);
53                 System::jsonError(422, $errorobj->toArray());
54         }
55
56         public function Unauthorized(string $error = '')
57         {
58                 $error = $error ?: DI::l10n()->t('Unauthorized');
59                 $error_description = '';
60                 $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
61
62                 $this->logError(401, $error);
63                 System::jsonError(401, $errorobj->toArray());
64         }
65
66         public function Forbidden(string $error = '')
67         {
68                 $error = $error ?: DI::l10n()->t('Token is not authorized with a valid user or is missing a required scope');
69                 $error_description = '';
70                 $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
71
72                 $this->logError(403, $error);
73                 System::jsonError(403, $errorobj->toArray());
74         }
75
76         public function InternalError(string $error = '')
77         {
78                 $error = $error ?: DI::l10n()->t('Internal Server Error');
79                 $error_description = '';
80                 $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
81
82                 $this->logError(500, $error);
83                 System::jsonError(500, $errorobj->toArray());
84         }
85 }