From f6579d0716fc05901d95d4247e0f5c0364ab3d38 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 4 Oct 2015 19:46:24 +0000 Subject: 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. --- static/classes/Response.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'static/classes/Response.class.php') 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; } } -- cgit v1.2.3