Throw exceptions as appropriate, but allow the Kohana exception

handling framework to handle the exception and delegate to our
template, which will JSON encode the response.
This commit is contained in:
Bharat Mediratta
2010-06-19 13:53:22 -07:00
parent 41ca2b0195
commit 456d54ea2d
3 changed files with 17 additions and 37 deletions

View File

@@ -18,13 +18,20 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Rest_Exception_Core extends Kohana_Exception {
public function __construct($message, $code) {
var $response = array();
public function __construct($message, $code, $response) {
parent::__construct($message, null, $code);
$this->response = $response;
}
public function sendHeaders() {
if (!headers_sent()) {
header("HTTP/1.1 " . $this->getCode() . "Bad Request");
header("HTTP/1.1 " . $this->getCode() . " " . $this->getMessage());
}
}
public function getTemplate() {
return "error_rest";
}
}