$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Item::performActivity($item['id'], 'dislike', $uid);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::DISLIKE, 'deleted' => false]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Item::performActivity($item['id'], 'undislike', $uid);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id']) && empty($this->parameters['name'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!empty($this->parameters['id'])) {
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
} else {
$contact = Contact::selectFirst(['id'], ['nick' => $this->parameters['name'], 'uid' => 0]);
if (!empty($contact['id'])) {
$id = $contact['id'];
} elseif (!($id = Contact::getIdForURL($this->parameters['name'], 0, false))) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setBlocked($this->parameters['id'], $uid, true);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$lists = [];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setIgnored($this->parameters['id'], $uid, true);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
if (empty($cdata['user'])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]);
], $request);
if (empty($request['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!is_array($request['id'])) {
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setBlocked($this->parameters['id'], $uid, false);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
if (empty($cdata['user'])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$contact = Contact::getById($cdata['user']);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Contact\User::setIgnored($this->parameters['id'], $uid, false);
}
if (empty($request['client_name']) || empty($request['redirect_uris'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters')));
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters')));
}
$client_id = bin2hex(random_bytes(32));
}
if (!DBA::insert('application', $fields)) {
- $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
+ $this->logAndJsonError(500, $this->errorFactory->InternalError());
}
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray());
$application = self::getCurrentApplication();
if (empty($application['id'])) {
- $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
+ $this->logAndJsonError(401, $this->errorFactory->Unauthorized());
}
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id']));
$uid = self::getCurrentUserID();
if (!empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
DBA::delete('conv', ['id' => $this->parameters['id'], 'uid' => $uid]);
$conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']);
}
} catch (NotFoundException $e) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
DBA::close($convs);
$uid = self::getCurrentUserID();
if (!empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]);
try {
$this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray());
} catch (NotFoundException $e) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}
}
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!Circle::exists($this->parameters['id'], $uid)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!Circle::remove($this->parameters['id'])) {
- $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
+ $this->logAndJsonError(500, $this->errorFactory->InternalError());
}
$this->jsonExit([]);
], $request);
if (empty($request['title'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Circle::create($uid, $request['title']);
$id = Circle::getIdByName($uid, $request['title']);
if (!$id) {
- $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
+ $this->logAndJsonError(500, $this->errorFactory->InternalError());
}
$this->jsonExit(DI::mstdnList()->createFromCircleId($id));
], $request);
if (empty($request['title']) || empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Circle::update($this->parameters['id'], $request['title']);
$id = $this->parameters['id'];
if (!Circle::exists($id, $uid)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$lists = DI::mstdnList()->createFromCircleId($id);
}
], $request);
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
return Circle::removeMembers($this->parameters['id'], $request['account_ids']);
], $request);
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Circle::addMembers($this->parameters['id'], $request['account_ids']);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([
}
if (empty($timeline) || empty($last_read_id) || empty($application['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(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'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$media = Photo::upload($uid, $_FILES['file'], '', null, null, '', '', $request['description']);
if (empty($media)) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
Logger::info('Uploaded photo', ['media' => $media]);
], $request);
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$photo = Photo::selectFirst(['resource-id'], ['id' => $this->parameters['id'], 'uid' => $uid]);
if (empty($photo['resource-id'])) {
$media = Post\Media::getById($this->parameters['id']);
if (empty($media['uri-id'])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!Post::exists(['uri-id' => $media['uri-id'], 'uid' => $uid, 'origin' => true])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Post\Media::updateById(['description' => $request['description']], $this->parameters['id']);
$this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id']));
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!Photo::exists(['id' => $id, 'uid' => $uid])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($id));
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$request = $this->getRequest([
$notification = DI::notification()->selectOneForUser($uid, ['id' => $id]);
$this->jsonExit(DI::mstdnNotification()->createFromNotification($notification, self::appSupportsQuotes()));
} catch (\Exception $e) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$condition = ['id' => $this->parameters['id']];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$this->jsonExit(DI::mstdnPoll()->createFromId($this->parameters['id'], $uid));
$subscription = Subscription::select($application['id'], $uid, ['id']);
if (empty($subscription)) {
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]);
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$fields = [
if (!Subscription::exists($application['id'], $uid)) {
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]);
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$this->logger->info('Fetch subscription', ['application-id' => $application['id'], 'uid' => $uid]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!DBA::exists('delayed-post', ['id' => $this->parameters['id'], 'uid' => $uid])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Post\Delayed::deleteById($this->parameters['id']);
], $request);
if (empty($request['q'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$limit = min($request['limit'], 40);
$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)) {
- $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
+ $this->logAndJsonError(500, $this->errorFactory->InternalError());
}
$this->jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($id, $uid)->toArray());
}
}
}
- $this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
+ $this->logAndJsonError(500, $this->errorFactory->InternalError());
}
protected function delete(array $request = [])
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]);
if (empty($item['id'])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!Item::markForDeletionById($item['id'])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$this->jsonExit([]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), false));
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked')));
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked')));
}
if ($item['uid'] == 0) {
if (!empty($stored)) {
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
} else {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(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'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
}
DBA::close($posts);
} else {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Item::performActivity($item['id'], 'like', $uid);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be muted')));
+ $this->logAndJsonError(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'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], $uid);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['network'] == Protocol::DIASPORA) {
Diaspora::performReshare($this->parameters['id'], $uid);
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
- $this->logErrorAndJsonExit(
+ $this->logAndJsonError(
422,
$this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])))
);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$id = $this->parameters['id'];
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked')));
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked')));
}
if ($item['uid'] == 0) {
if (!empty($stored)) {
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
} else {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
}
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Item::performActivity($item['id'], 'unlike', $uid);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['gravity'] != Item::GRAVITY_PARENT) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unmuted')));
+ $this->logAndJsonError(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'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if ($item['network'] == Protocol::DIASPORA) {
$item = Post::selectFirstForUser($uid, ['id'], ['quote-uri-id' => $this->parameters['id'], 'body' => '', 'origin' => true, 'uid' => $uid]);
if (empty($item['id'])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!Item::markForDeletionById($item['id'])) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
- $this->logErrorAndJsonExit(
+ $this->logAndJsonError(
422,
$this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])))
);
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$tag = ltrim($this->parameters['hashtag'], '#');
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$fields = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$term = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
$statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']);
}
} catch (NotFoundException $e) {
- $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
+ $this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
}
if (!empty($request['min_id'])) {
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
$request = $this->getRequest([
$uid = self::getCurrentUserID();
if (empty($this->parameters['hashtag'])) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
/**
if (empty($token)) {
$this->logger->notice('Empty application token');
- $this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
+ $this->logAndJsonError(403, $this->errorFactory->Forbidden());
}
if (!isset($token[$scope])) {
$this->logger->warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]);
- $this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
+ $this->logAndJsonError(403, $this->errorFactory->Forbidden());
}
if (empty($token[$scope])) {
$this->logger->warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]);
- $this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
+ $this->logAndJsonError(403, $this->errorFactory->Forbidden());
}
}
* @return void
* @throws HTTPException\InternalServerErrorException
*/
- protected function logErrorAndJsonExit(int $errorno, Error $error)
+ protected function logAndJsonError(int $errorno, Error $error)
{
$this->logger->info('API Error', ['no' => $errorno, 'error' => $error->toArray(), 'method' => $this->args->getMethod(), 'command' => $this->args->getQueryString(), 'user-agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
$this->jsonError(403, $error->toArray());
if ($request['response_type'] != 'code') {
Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]);
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing response type')));
+ $this->logAndJsonError(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]);
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data')));
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data')));
}
$application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
if (empty($application)) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
// @todo Compare the application scope and requested scope
$token = OAuth::createTokenForUser($application, $uid, $request['scope']);
if (!$token) {
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
+ $this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
}
if ($application['redirect_uri'] != 'urn:ietf:wg:oauth:2.0:oob') {
$token = DBA::selectFirst('application-view', ['id'], $condition);
if (empty($token['id'])) {
$this->logger->notice('Token not found', $condition);
- $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
+ $this->logAndJsonError(401, $this->errorFactory->Unauthorized());
}
DBA::delete('application-token', ['application-id' => $token['id']]);
if (empty($request['client_id']) || empty($request['client_secret'])) {
$this->logger->warning('Incomplete request data', ['request' => $request]);
- $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Incomplete request data')));;
+ $this->logAndJsonError(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Incomplete request data')));;
}
$application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
if (empty($application)) {
- $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client')));
+ $this->logAndJsonError(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client')));
}
if ($request['grant_type'] == 'client_credentials') {
$token = DBA::selectFirst('application-view', ['access_token', 'created_at', 'uid'], $condition);
if (!DBA::isResult($token)) {
$this->logger->notice('Token not found or outdated', $condition);
- $this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
+ $this->logAndJsonError(401, $this->errorFactory->Unauthorized());
}
$owner = User::getOwnerDataById($token['uid']);
$me = $owner['url'];
} else {
Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]);
- $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing grant type')));
+ $this->logAndJsonError(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);