ArgumentNotExistException.php
10 years ago
EmptyArgumentException.php
10 years ago
Exception.php
10 years ago
InvalidArgumentException.php
10 years ago
OAuthException.php
10 years ago
Exception.php
75 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Thrown when an API call returns an exception. |
| 4 | * |
| 5 | */ |
| 6 | class Freemius_Exception extends Exception |
| 7 | { |
| 8 | protected $_result; |
| 9 | protected $_type; |
| 10 | protected $_code; |
| 11 | |
| 12 | /** |
| 13 | * Make a new API Exception with the given result. |
| 14 | * |
| 15 | * @param array $result The result from the API server. |
| 16 | */ |
| 17 | public function __construct($result) |
| 18 | { |
| 19 | $this->_result = $result; |
| 20 | |
| 21 | $code = 0; |
| 22 | $message = 'Unknown error, please check GetResult().'; |
| 23 | $type = ''; |
| 24 | |
| 25 | if (isset($result['error']) && is_array($result['error'])) |
| 26 | { |
| 27 | if (isset($result['error']['code'])) |
| 28 | $code = $result['error']['code']; |
| 29 | if (isset($result['error']['message'])) |
| 30 | $message = $result['error']['message']; |
| 31 | if (isset($result['error']['type'])) |
| 32 | $type = $result['error']['type']; |
| 33 | } |
| 34 | |
| 35 | $this->_type = $type; |
| 36 | $this->_code = $code; |
| 37 | |
| 38 | parent::__construct($message, is_numeric($code) ? $code : 0); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Return the associated result object returned by the API server. |
| 43 | * |
| 44 | * @return array The result from the API server |
| 45 | */ |
| 46 | public function getResult() |
| 47 | { |
| 48 | return $this->_result; |
| 49 | } |
| 50 | |
| 51 | public function getStringCode() |
| 52 | { |
| 53 | return $this->_code; |
| 54 | } |
| 55 | |
| 56 | public function getType() |
| 57 | { |
| 58 | return $this->_type; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * To make debugging easier. |
| 63 | * |
| 64 | * @return string The string representation of the error |
| 65 | */ |
| 66 | public function __toString() |
| 67 | { |
| 68 | $str = $this->getType() . ': '; |
| 69 | |
| 70 | if ($this->code != 0) |
| 71 | $str .= $this->getStringCode() . ': '; |
| 72 | |
| 73 | return $str . $this->getMessage(); |
| 74 | } |
| 75 | } |