| @@ 9-43 (lines=35) @@ | ||
| 6 | * The system exception can be used for showing a system error like a missing file or a broken connection. |
|
| 7 | * @author Christian Blank <[email protected]> |
|
| 8 | */ |
|
| 9 | class RestSystemException extends \Exception { |
|
| 10 | /* |
|
| 11 | * @var int - override the default http status code if needed |
|
| 12 | */ |
|
| 13 | protected $httpStatusCode; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * RestSystemException constructor. |
|
| 17 | * @param string $message the error message |
|
| 18 | * @param int $errorCode the error code of the api |
|
| 19 | * @param int $httpStatusCode the http status code in the response; Default=500 |
|
| 20 | */ |
|
| 21 | public function __construct($message, $errorCode, $httpStatusCode = 500) { |
|
| 22 | parent::__construct($message, $errorCode); |
|
| 23 | $this->httpStatusCode = $httpStatusCode; |
|
| 24 | } |
|
| 25 | ||
| 26 | ||
| 27 | /** |
|
| 28 | * @return int |
|
| 29 | */ |
|
| 30 | public function getHttpStatusCode() { |
|
| 31 | return $this->httpStatusCode; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @param int $httpStatusCode |
|
| 36 | * @return $this |
|
| 37 | */ |
|
| 38 | public function setHttpStatusCode($httpStatusCode) { |
|
| 39 | $this->httpStatusCode = $httpStatusCode; |
|
| 40 | return $this; |
|
| 41 | } |
|
| 42 | ||
| 43 | } |
|
| 44 | ||
| @@ 9-42 (lines=34) @@ | ||
| 6 | * The user exception can be used for indicating the wrong usage of the rest api. |
|
| 7 | * @author Christian Blank <[email protected]> |
|
| 8 | */ |
|
| 9 | class RestUserException extends \Exception { |
|
| 10 | ||
| 11 | /** |
|
| 12 | * @var int - override the default http status code if needed |
|
| 13 | */ |
|
| 14 | protected $httpStatusCode = 400; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @param string $message |
|
| 18 | * @param int $errorCode |
|
| 19 | * @param int $httpStatusCode |
|
| 20 | */ |
|
| 21 | public function __construct($message, $errorCode, $httpStatusCode = 400) { |
|
| 22 | parent::__construct($message, $errorCode); |
|
| 23 | $this->httpStatusCode = $httpStatusCode; |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @return int |
|
| 28 | */ |
|
| 29 | public function getHttpStatusCode() { |
|
| 30 | return $this->httpStatusCode; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @param int $httpStatusCode |
|
| 35 | * @return $this |
|
| 36 | */ |
|
| 37 | public function setHttpStatusCode($httpStatusCode) { |
|
| 38 | $this->httpStatusCode = $httpStatusCode; |
|
| 39 | return $this; |
|
| 40 | } |
|
| 41 | ||
| 42 | } |
|
| 43 | ||