summaryrefslogtreecommitdiff
path: root/actions/api.php
diff options
context:
space:
mode:
authorzach <zach@copley.name>2008-07-20 03:09:05 -0400
committerzach <zach@copley.name>2008-07-20 03:09:05 -0400
commit140689800b03ff704f6c70260c2b740ad41578c0 (patch)
tree7d9fe90e1ae731f9275910302ec6063df2486d62 /actions/api.php
parent00a6f3d01510e01a5dcc0999a50fba7bafbcd5e1 (diff)
Twitter-compatible API - Error handling that better matches Twitter's
darcs-hash:20080720070905-ca946-dda57dd92210461361fd58b7a3244bf24c01e801.gz
Diffstat (limited to 'actions/api.php')
-rw-r--r--actions/api.php15
1 files changed, 10 insertions, 5 deletions
diff --git a/actions/api.php b/actions/api.php
index a52570320..69fda2e22 100644
--- a/actions/api.php
+++ b/actions/api.php
@@ -45,9 +45,7 @@ class ApiAction extends Action {
$this->api_method = $cmdext[0];
$this->content_type = strtolower($cmdext[1]);
}
-
- # common_debug("apiaction = $this->api_action, method = $this->api_method, argument = $this->api_arg, ctype = $this->content_type");
-
+
# XXX Maybe check to see if the command actually exists first?
if($this->requires_auth()) {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
@@ -56,7 +54,7 @@ class ApiAction extends Action {
header('WWW-Authenticate: Basic realm="Laconica API"');
# if the user hits cancel -- bam!
- common_show_basic_auth_error();
+ $this->show_basic_auth_error();
} else {
$nickname = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
@@ -67,7 +65,7 @@ class ApiAction extends Action {
$this->process_command();
} else {
# basic authentication failed
- common_show_basic_auth_error();
+ $this->show_basic_auth_error();
}
}
} else {
@@ -123,5 +121,12 @@ class ApiAction extends Action {
return true;
}
}
+
+ function show_basic_auth_error() {
+ header('HTTP/1.1 401 Unauthorized');
+ header('Content-type: text/plain');
+ print("Could not authenticate you."); # exactly what Twitter says - no \n
+ exit();
+ }
}