This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathException.php
executable file
·57 lines (54 loc) · 1.56 KB
/
Exception.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* REST_Exception
*
* The purpose of class is to provide posibility to work with rest errors
* through exceptions and then handle it in error controller.
*
* Default error http code is 400
*
* Example
* <code>
* switch ($errors->type) {
* case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
* case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
* case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
* // 404 error -- controller or action not found
* $this->view->errorMessages[] = 'Page not found';
* $this->getResponse()->setHttpResponseCode(404);
* break;
*
* default:
* // application error
*
* $message = 'Application error';
* $httpCode = 500;
*
* if (($exception = $this->getResponse()->getException())
* && ($exception[0] instanceof REST_Exception)
* ){
* $message = $exception[0]->getMessage();
* $httpCode = $exception[0]->getHttpCode();
* }
*
* $this->view->errorMessages[] = $message;
* $this->getResponse()->setHttpResponseCode($httpCode);
* break;
* }
* </code>
*
* @author Yuriy Ishchenko <[email protected]>
*/
class REST_Exception extends Exception
{
protected $httpCode;
public function __construct($message, $httpCode = REST_Response::BAD_REQUEST)
{
parent::__construct($message);
$this->httpCode = $httpCode;
}
public function getHttpCode()
{
return $this->httpCode;
}
}