set api format so client errors work

This commit is contained in:
Hannes Mannerheim 2016-02-01 18:22:35 +01:00
parent e1554be53b
commit 7285e3a8b4
19 changed files with 49 additions and 16 deletions

View File

@ -57,6 +57,8 @@ class ApiAccountUpdateProfileBannerAction extends ApiAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->user = $this->auth_user;
$this->cropW = $this->trimmed('width');

View File

@ -46,6 +46,8 @@ class ApiExternalUserShowAction extends ApiPrivateAuthAction
{
parent::prepare($args);
$this->format = 'json';
$profileurl = urldecode($this->arg('profileurl'));
$nickname = urldecode($this->arg('nickname'));

View File

@ -46,14 +46,15 @@ class ApiFavsAndRepeatsAction extends ApiPrivateAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->notice_id = $this->trimmed('notice_id');
$this->original = Notice::getKV('id', $this->notice_id);
if (empty($this->original)) {
// TRANS: Client error displayed trying to display redents of a non-exiting notice.
$this->clientError(_('No such notice.'),
400, $this->format);
$this->clientError(_('No such notice.'), 400);
return false;
}

View File

@ -62,6 +62,8 @@ class ApiQvitterAllFollowingAction extends ApiBareAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->count = 5000; // max 5000, completely arbitrary...
$this->target = $this->getTargetProfile($this->arg('id'));

View File

@ -43,7 +43,7 @@ if (!defined('STATUSNET')) {
}
class ApiQvitterBlocksAction extends ApiBareAuthAction
class ApiQvitterBlocksAction extends ApiPrivateAuthAction
{
var $profiles = null;
@ -58,15 +58,20 @@ class ApiQvitterBlocksAction extends ApiBareAuthAction
{
parent::prepare($args);
// If called as a social graph method, show 5000 per page, otherwise 100
$this->format = 'json';
$this->count = (int)$this->arg('count', 100);
$this->target = $this->getTargetProfile($this->arg('id'));
$arg_user = $this->getTargetUser($this->arg('id'));
$this->target = ($this->auth_user) ? $this->auth_user->getProfile() : null;
if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting a list of followers for a non-existing user.
$this->clientError(_('No such user.'), 404);
} else if($this->auth_user->id != $arg_user->id) {
$this->clientError(_('You are only allowed to view your own blocks.'), 403);
}
$this->profiles = $this->getProfiles();

View File

@ -39,6 +39,8 @@ class ApiQvitterCheckEmailAction extends ApiAction
{
parent::prepare($args);
$this->format = 'json';
$this->email = $this->trimmed('email');
if(!Validate::email($this->email, common_config('email', 'check_domain'))) {

View File

@ -61,19 +61,16 @@ class ApiQvitterCheckLoginAction extends ApiAction
{
parent::handle();
$this->format = 'json';
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400,
$this->format
);
$this->clientError(_('This method requires a POST.'), 400);
return;
}
$user = common_check_user($this->arg('username'),
$this->arg('password'));
$this->arg('password'));
if($user) {
$user = true;
}

View File

@ -65,6 +65,8 @@ class ApiQvitterListMembersAction extends ApiPrivateAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->list = $this->getTargetList($this->arg('nickname'), $this->arg('id'));
if (!$this->list instanceof Profile_list) {
// TRANS: Client error displayed trying to show list membership on a non-existing list.

View File

@ -65,6 +65,8 @@ class ApiQvitterListSubscribersAction extends ApiPrivateAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->list = $this->getTargetList($this->arg('nickname'), $this->arg('id'));
if (!$this->list instanceof Profile_list) {
// TRANS: Client error displayed trying to show list membership on a non-existing list.

View File

@ -55,6 +55,8 @@ class ApiQvitterNotificationsAction extends ApiPrivateAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->notifications = $this->getNotifications();
return true;

View File

@ -199,12 +199,12 @@ class ApiQvitterStatusesUpdateAction extends ApiAuthAction
'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']), 400);
}
if (empty($this->status)) {
// TRANS: Client error displayed when the parameter "status" is missing.
$this->clientError(_('Client must provide a \'status\' parameter with a value.'));
$this->clientError(_('Client must provide a \'status\' parameter with a value.'), 400);
}
if (is_null($this->scoped)) {

View File

@ -58,6 +58,8 @@ class ApiQvitterTimelineListAction extends ApiBareAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->list = $this->getTargetList($this->arg('nickname'), $this->arg('id'));
if (!($this->list instanceof Profile_list)) {
// TRANS: Client error displayed when requesting a non existing list

View File

@ -53,6 +53,8 @@ class ApiQvitterUpdateBackgroundColorAction extends ApiAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->backgroundcolor = $this->trimmed('backgroundcolor');
return true;
}

View File

@ -58,6 +58,8 @@ class ApiQvitterUpdateBookmarksAction extends ApiAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->bookmarks = $this->trimmed('bookmarks');
return true;

View File

@ -54,6 +54,8 @@ class ApiQvitterUpdateLinkColorAction extends ApiAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->linkcolor = $this->trimmed('linkcolor');
return true;

View File

@ -56,6 +56,8 @@ class ApiSavedSearchesListAction extends ApiAuthAction
{
parent::prepare($args);
$this->format = 'json';
return true;
}

View File

@ -56,6 +56,8 @@ class ApiTrendsPlaceAction extends ApiAuthAction
{
parent::prepare($args);
$this->format = 'json';
return true;
}

View File

@ -57,6 +57,8 @@ class ApiUpdateAvatarAction extends ApiAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->user = $this->auth_user;
$this->cropW = $this->trimmed('cropW');

View File

@ -57,6 +57,8 @@ class ApiUpdateBackgroundImageAction extends ApiAuthAction
{
parent::prepare($args);
$this->format = 'json';
$this->user = $this->auth_user;
$this->cropW = $this->trimmed('cropW');