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