From 30849d10b151582fff67fd41fef1177396e47996 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 10 Jun 2010 08:18:15 -0700 Subject: Tweak the error response for rest requests to make it easier for the client to extract error information. --- modules/rest/controllers/rest.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'modules/rest') 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 -- cgit v1.2.3