Twitter API returns server errors in preferred format
This commit is contained in:
parent
b0ce2add41
commit
f46084309b
|
@ -297,7 +297,7 @@ class TwitapistatusesAction extends TwitterapiAction
|
|||
$source, 1, $reply_to);
|
||||
|
||||
if (is_string($notice)) {
|
||||
$this->serverError($notice);
|
||||
$this->serverError($notice, 500, $apidata['content-type']);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -939,35 +939,16 @@ class TwitterapiAction extends Action
|
|||
|
||||
function clientError($msg, $code = 400, $content_type = 'json')
|
||||
{
|
||||
|
||||
static $status = array(400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Timeout',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
417 => 'Expectation Failed');
|
||||
|
||||
$action = $this->trimmed('action');
|
||||
|
||||
common_debug("User error '$code' on '$action': $msg", __FILE__);
|
||||
|
||||
if (!array_key_exists($code, $status)) {
|
||||
if (!array_key_exists($code, ClientErrorAction::$status)) {
|
||||
$code = 400;
|
||||
}
|
||||
|
||||
$status_string = $status[$code];
|
||||
$status_string = ClientErrorAction::$status[$code];
|
||||
|
||||
header('HTTP/1.1 '.$code.' '.$status_string);
|
||||
|
||||
if ($content_type == 'xml') {
|
||||
|
@ -986,6 +967,35 @@ class TwitterapiAction extends Action
|
|||
|
||||
}
|
||||
|
||||
function serverError($msg, $code = 500, $content_type = 'json')
|
||||
{
|
||||
$action = $this->trimmed('action');
|
||||
|
||||
common_debug("Server error '$code' on '$action': $msg", __FILE__);
|
||||
|
||||
if (!array_key_exists($code, ServerErrorAction::$status)) {
|
||||
$code = 400;
|
||||
}
|
||||
|
||||
$status_string = ServerErrorAction::$status[$code];
|
||||
|
||||
header('HTTP/1.1 '.$code.' '.$status_string);
|
||||
|
||||
if ($content_type == 'xml') {
|
||||
$this->init_document('xml');
|
||||
$this->elementStart('hash');
|
||||
$this->element('error', null, $msg);
|
||||
$this->element('request', null, $_SERVER['REQUEST_URI']);
|
||||
$this->elementEnd('hash');
|
||||
$this->end_document('xml');
|
||||
} else {
|
||||
$this->init_document('json');
|
||||
$error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
|
||||
print(json_encode($error_array));
|
||||
$this->end_document('json');
|
||||
}
|
||||
}
|
||||
|
||||
function init_twitter_rss()
|
||||
{
|
||||
$this->startXML();
|
||||
|
|
Loading…
Reference in New Issue
Block a user