summaryrefslogtreecommitdiff
path: root/static/classes/Response.class.php
diff options
context:
space:
mode:
authorJuuso Lapinlampi <wub@partyvan.eu>2015-10-04 21:46:24 +0200
committerJuuso Lapinlampi <wub@partyvan.eu>2015-10-04 22:03:23 +0200
commitf6579d0716fc05901d95d4247e0f5c0364ab3d38 (patch)
tree640a08b67eb0c6b091f69c1e912d88adccbc2d22 /static/classes/Response.class.php
parent760b1dda71e706a9014b85d34025874e9ef7bbeb (diff)
JSON-ify the default invalid response type error
Code re-use is good. The previous implementation doesn't reuse existing text_error() functions and also forgoes using text/plain header with the text implementation. This fixes consistency where JSON is assumed to be the default output. It is a common practice among APIs to default all errors to JSON, such as the Stripe and Tumblr APIs.
Diffstat (limited to 'static/classes/Response.class.php')
-rwxr-xr-xstatic/classes/Response.class.php5
1 files changed, 3 insertions, 2 deletions
diff --git a/static/classes/Response.class.php b/static/classes/Response.class.php
index cd9229b..a4e19b5 100755
--- a/static/classes/Response.class.php
+++ b/static/classes/Response.class.php
@@ -50,8 +50,9 @@ class Response
$this->type = $response_type;
break;
default:
- http_response_code(400);
- echo 'Invalid response type. Valid options are: csv, html, json, text.';
+ header('Content-Type: application/json; charset=UTF-8');
+ $this->type = 'json';
+ $this->error(400, 'Invalid response type. Valid options are: csv, html, json, text.');
break;
}
}