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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?php if ( ! class_exists( 'Freemius_Exception' ) ) { /** * Thrown when an API call returns an exception. * */ class Freemius_Exception extends Exception { protected $_result; protected $_type; protected $_code;
/** * Make a new API Exception with the given result. * * @param array $result The result from the API server. */ public function __construct( $result ) { $this->_result = $result;
$code = 0; $message = 'Unknown error, please check GetResult().'; $type = '';
if ( isset( $result['error'] ) && is_array( $result['error'] ) ) { if ( isset( $result['error']['code'] ) ) { $code = $result['error']['code']; } if ( isset( $result['error']['message'] ) ) { $message = $result['error']['message']; } if ( isset( $result['error']['type'] ) ) { $type = $result['error']['type']; } }
$this->_type = $type; $this->_code = $code;
parent::__construct( $message, is_numeric( $code ) ? $code : 0 ); }
/** * Return the associated result object returned by the API server. * * @return array The result from the API server */ public function getResult() { return $this->_result; }
public function getStringCode() { return $this->_code; }
public function getType() { return $this->_type; }
/** * To make debugging easier. * * @return string The string representation of the error */ public function __toString() { $str = $this->getType() . ': ';
if ( $this->code != 0 ) { $str .= $this->getStringCode() . ': '; }
return $str . $this->getMessage(); } } }
|