From: Zach Copley Date: Wed, 30 Sep 2009 17:32:05 +0000 (-0700) Subject: Merge branch '0.9.x' into refactor-api X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5bab0288afe90996729101df1372071e1bf2cffc;p=quix0rs-gnu-social.git Merge branch '0.9.x' into refactor-api * 0.9.x: (39 commits) Timeout a little incase the notice item from XHR response is Relocated the button for pop up window for notice stream Script no longer needed for Realtime plugin Better check to see if the XML prolog should be outputted for XML Outputting UTF-8 charset in document header irrespective of mimetype. Switched Doctype to XHTML 1.0 Strict (which best reflects the current Twitter API returns server errors in preferred format move HTTP error code strings to class variables remove string-checks from code using Notice::saveNew() change string return from Notice::saveNew to exceptions stop overwriting created timestamp on group edit Forgot to add home_timeline to the list of methods that only require Forgot to add home_timeline to the list of methods that only require moderator can delete another user's notice show delete button when user has deleteOthersNotice right let hooks override standard user rights user rights Merge DeleteAction class into DeletenoticeAction Fix some bugs in the URL linkification, and fixed the unit test. Fix URL linkification test cases for addition of 'title' attribution with long URL in f3c8fccc ... --- 5bab0288afe90996729101df1372071e1bf2cffc diff --cc lib/twitterapi.php index 6014a340eb,4a5de6ab3a..708738832b --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@@ -932,28 -934,8 +932,8 @@@ class TwitterapiAction extends Actio return; } - function clientError($msg, $code = 400, $content_type = 'json') + function clientError($msg, $code = 400, $format = 'xml') { - - 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__); @@@ -962,10 -944,11 +942,11 @@@ $code = 400; } - $status_string = $status[$code]; + $status_string = ClientErrorAction::$status[$code]; + header('HTTP/1.1 '.$code.' '.$status_string); - if ($content_type == 'xml') { + if ($format == 'xml') { $this->init_document('xml'); $this->elementStart('hash'); $this->element('error', null, $msg); @@@ -977,13 -960,39 +958,42 @@@ $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']); print(json_encode($error_array)); $this->end_document('json'); - } + } else { + // If user didn't request a useful format, throw a regular client error + throw new ClientException($msg, $code); + } } + 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();