summaryrefslogtreecommitdiff
path: root/modules/rest/libraries
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-12-31 11:51:51 -0800
committerTim Almdal <tnalmdal@shaw.ca>2009-12-31 11:51:51 -0800
commit1a12a5e3c89c41ebd087591c16611fbab4293f5b (patch)
treeedba677930997890f1a9a24922bcd06f2dd7ed14 /modules/rest/libraries
parent732047e9c3cbd178acd07c531ed78afade9a4918 (diff)
Create a Rest_Exception class and use it to convey status to the client instead of calling rest::forbidden and other rest helper error messages.
Diffstat (limited to 'modules/rest/libraries')
-rw-r--r--modules/rest/libraries/Rest_Exception.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/modules/rest/libraries/Rest_Exception.php b/modules/rest/libraries/Rest_Exception.php
new file mode 100644
index 00000000..acdcb568
--- /dev/null
+++ b/modules/rest/libraries/Rest_Exception.php
@@ -0,0 +1,41 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+/**
+ * Creates a "Page Not Found" exception.
+ *
+ * $Id: Kohana_404_Exception.php 4679 2009-11-10 01:45:52Z isaiah $
+ *
+ * @package Core
+ * @author Kohana Team
+ * @copyright (c) 2007-2009 Kohana Team
+ * @license http://kohanaphp.com/license
+ */
+
+class Rest_Exception_Core extends Exception {
+ /**
+ * Set internal properties.
+ */
+ public function __construct($code, $text) {
+ parent::__construct("$code $text");
+ }
+
+ /**
+ * Throws a new Rest exception.
+ *
+ * @throws Rest_Exception
+ * @return void
+ */
+ public static function trigger($code, $text, $log_message=null) {
+ $message = "$code: $text" . (!empty($log_message) ? "\n$log_message" : "");
+ Kohana_Log::add("info", $message);
+ throw new Rest_Exception($code, $text);
+ }
+
+ /**
+ * Sends the headers, to emulate server behavior.
+ *
+ * @return void
+ */
+ public function sendHeaders() {
+ header('HTTP/1.1 {$this->getMessage()}');
+ }
+} // End Rest Exception \ No newline at end of file