return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
}
- public function UnprocessableEntity(string $error = '')
+ public function UnprocessableEntity(string $error = ''): \Friendica\Object\Api\Mastodon\Error
{
$error = $error ?: $this->l10n->t('Unprocessable Entity');
$error_description = '';
- $errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
-
- $this->logError(422, $error);
- $this->jsonError(422, $errorObj->toArray());
+ return new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
}
public function Unauthorized(string $error = '', string $error_description = '')
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id']) && empty($this->parameters['name'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
if (!empty($this->parameters['id'])) {
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setBlocked($this->parameters['id'], $uid, true);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setIgnored($this->parameters['id'], $uid, true);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
], $request);
if (empty($request['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
if (!is_array($request['id'])) {
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setBlocked($this->parameters['id'], $uid, false);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setIgnored($this->parameters['id'], $uid, false);
}
if (empty($request['client_name']) || empty($request['redirect_uris'])) {
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Missing parameters'));
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters')));
}
$client_id = bin2hex(random_bytes(32));
$uid = self::getCurrentUserID();
if (!empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
DBA::delete('conv', ['id' => $this->parameters['id'], 'uid' => $uid]);
$uid = self::getCurrentUserID();
if (!empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
if (!Circle::exists($this->parameters['id'], $uid)) {
], $request);
if (empty($request['title'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
Circle::create($uid, $request['title']);
], $request);
if (empty($request['title']) || empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
Circle::update($this->parameters['id'], $request['title']);
], $request);
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
return Circle::removeMembers($this->parameters['id'], $request['account_ids']);
], $request);
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
Circle::addMembers($this->parameters['id'], $request['account_ids']);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
}
if (empty($timeline) || empty($last_read_id) || empty($application['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$condition = ['application-id' => $application['id'], 'uid' => $uid, 'timeline' => $timeline];
Logger::info('Photo post', ['request' => $request, 'files' => $_FILES]);
if (empty($_FILES['file'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$media = Photo::upload($uid, $_FILES['file'], '', null, null, '', '', $request['description']);
if (empty($media)) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
Logger::info('Uploaded photo', ['media' => $media]);
], $request);
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$photo = Photo::selectFirst(['resource-id'], ['id' => $this->parameters['id'], 'uid' => $uid]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$condition = ['id' => $this->parameters['id']];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$this->jsonExit(DI::mstdnPoll()->createFromId($this->parameters['id'], $uid));
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
if (!DBA::exists('delayed-post', ['id' => $this->parameters['id'], 'uid' => $uid])) {
], $request);
if (empty($request['q'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$limit = min($request['limit'], 40);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), false));
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be bookmarked'));
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked')));
}
if ($item['uid'] == 0) {
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be muted'));
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be muted')));
}
Post\ThreadUser::setIgnored($item['uri-id'], $uid, true);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if ($item['network'] == Protocol::DIASPORA) {
Diaspora::performReshare($this->parameters['id'], $uid);
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])));
+ $this->logErrorAndJsonExit(
+ 422,
+ $this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])))
+ );
} else {
Item::performActivity($item['id'], 'announce', $uid);
}
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unbookmarked'));
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked')));
}
if ($item['uid'] == 0) {
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unmuted'));
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unmuted')));
}
Post\ThreadUser::setIgnored($item['uri-id'], $uid, false);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
}
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])));
+ $this->logErrorAndJsonExit(
+ 422,
+ $this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])))
+ );
} else {
Item::performActivity($item['id'], 'unannounce', $uid);
}
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$tag = ltrim($this->parameters['hashtag'], '#');
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$fields = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$term = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
/**
if ($request['response_type'] != 'code') {
Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]);
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing response type'));
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing response type')));
}
if (empty($request['client_id']) || empty($request['redirect_uri'])) {
Logger::warning('Incomplete request data', ['request' => $_REQUEST]);
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Incomplete request data'));
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data')));
}
$application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
if (empty($application)) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
// @todo Compare the application scope and requested scope
$token = OAuth::createTokenForUser($application, $uid, $request['scope']);
if (!$token) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
if ($application['redirect_uri'] != 'urn:ietf:wg:oauth:2.0:oob') {
$me = $owner['url'];
} else {
Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]);
- DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Unsupported or missing grant type'));
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing grant type')));
}
$object = new \Friendica\Object\Api\Mastodon\Token($token['access_token'], 'Bearer', $application['scopes'], $token['created_at'], $me);