diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2010-06-10 08:18:15 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2010-06-10 08:18:15 -0700 |
commit | 30849d10b151582fff67fd41fef1177396e47996 (patch) | |
tree | df10c35e5be9b5e204138dedabf3ea097ce3dc00 /modules/rest/controllers | |
parent | 6119ddc735ccfa6816b78bb7028c56dabf322019 (diff) |
Tweak the error response for rest requests to make it easier for the client to extract error information.
Diffstat (limited to 'modules/rest/controllers')
-rw-r--r-- | modules/rest/controllers/rest.php | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index 6392838f..3e364bff 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -93,28 +93,30 @@ class Rest_Controller extends Controller { // Add this exception to the log Kohana_Log::add('error', Kohana_Exception::text($e)); - $e->sendHeaders(); - $rest_exception = array(); if ($e instanceof ORM_Validation_Exception) { $detail_response = true; $rest_exception["code"] = 400; - $rest_exception["message"] = t("Validation errors"); - $rest_exception["fields"] = $e->validation->errors; + $rest_exception["message"] = "Validation errors"; + $rest_exception["fields"] = $e->validation->errors(); } else if ($e instanceof Rest_Exception) { $rest_exception["code"] = $e->getCode(); if ($e->getMessage() != "Bad Request") { $rest_exception["message"] = "Bad Request"; $rest_exception["fields"] = array("type", $e->getMessage()); - } else { + } else { $rest_exception["message"] = $e->getMessage(); } - header("HTTP/1.1 400 Bad Request"); } else { $rest_exception["code"] = 500; $rest_exception["message"] = t("Remote server call failed. Please contact the Adminstrator."); } + if (!headers_sent()) { + header($rest_exception["code"] == 500 ? "HTTP/1.1 500 Internal Server Error" : + "HTTP/1.1 400 Bad Request"); + } + return $rest_exception; } }
\ No newline at end of file |