| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
|
| 4 |
//260816 Legacy AWeber exception subclasses attach context dynamically; opt in explicitly on PHP 8.2+. |
| 5 |
#[\AllowDynamicProperties] |
| 6 |
class AWeberException extends Exception { } |
| 7 |
|
| 8 |
/** |
| 9 |
* Thrown when the API returns an error. (HTTP status >= 400) |
| 10 |
* |
| 11 |
* |
| 12 |
* @uses AWeberException |
| 13 |
* @package |
| 14 |
* @version $id$ |
| 15 |
*/ |
| 16 |
class AWeberAPIException extends AWeberException { |
| 17 |
|
| 18 |
public $type; |
| 19 |
public $status; |
| 20 |
public $message; |
| 21 |
public $documentation_url; |
| 22 |
public $url; |
| 23 |
|
| 24 |
public function __construct($error, $url) { |
| 25 |
// record specific details of the API exception for processing |
| 26 |
$this->url = $url; |
| 27 |
$this->type = $error['type']; |
| 28 |
$this->status = array_key_exists('status', $error) ? $error['status'] : ''; |
| 29 |
$this->message = $error['message']; |
| 30 |
$this->documentation_url = $error['documentation_url']; |
| 31 |
|
| 32 |
parent::__construct($this->message); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Thrown when attempting to use a resource that is not implemented. |
| 38 |
* |
| 39 |
* @uses AWeberException |
| 40 |
* @package |
| 41 |
* @version $id$ |
| 42 |
*/ |
| 43 |
class AWeberResourceNotImplemented extends AWeberException { |
| 44 |
|
| 45 |
public function __construct($object, $value) { |
| 46 |
$this->object = $object; |
| 47 |
$this->value = $value; |
| 48 |
parent::__construct("Resource \"{$value}\" is not implemented on this resource."); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* AWeberMethodNotImplemented |
| 54 |
* |
| 55 |
* Thrown when attempting to call a method that is not implemented for a resource |
| 56 |
* / collection. Differs from standard method not defined errors, as this will |
| 57 |
* be thrown when the method is infact implemented on the base class, but the |
| 58 |
* current resource type does not provide access to that method (ie calling |
| 59 |
* getByMessageNumber on a web_forms collection). |
| 60 |
* |
| 61 |
* @uses AWeberException |
| 62 |
* @package |
| 63 |
* @version $id$ |
| 64 |
*/ |
| 65 |
class AWeberMethodNotImplemented extends AWeberException { |
| 66 |
|
| 67 |
public function __construct($object) { |
| 68 |
$this->object = $object; |
| 69 |
parent::__construct("This method is not implemented by the current resource."); |
| 70 |
|
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* AWeberOAuthException |
| 76 |
* |
| 77 |
* OAuth exception, as generated by an API JSON error response |
| 78 |
* @uses AWeberException |
| 79 |
* @package |
| 80 |
* @version $id$ |
| 81 |
*/ |
| 82 |
class AWeberOAuthException extends AWeberException { |
| 83 |
|
| 84 |
public function __construct($type, $message) { |
| 85 |
$this->type = $type; |
| 86 |
$this->message = $message; |
| 87 |
parent::__construct("{$type}: {$message}"); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* AWeberOAuthDataMissing |
| 93 |
* |
| 94 |
* Used when a specific piece or pieces of data was not found in the |
| 95 |
* response. This differs from the exception that might be thrown as |
| 96 |
* an AWeberOAuthException when parameters are not provided because |
| 97 |
* it is not the servers' expectations that were not met, but rather |
| 98 |
* the expecations of the client were not met by the server. |
| 99 |
* |
| 100 |
* @uses AWeberException |
| 101 |
* @package |
| 102 |
* @version $id$ |
| 103 |
*/ |
| 104 |
class AWeberOAuthDataMissing extends AWeberException { |
| 105 |
|
| 106 |
public function __construct($missing) { |
| 107 |
if (!is_array($missing)) $missing = array($missing); |
| 108 |
$this->missing = $missing; |
| 109 |
$required = join(', ', $this->missing); |
| 110 |
parent::__construct("OAuthDataMissing: Response was expected to contain: {$required}"); |
| 111 |
|
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* AWeberResponseError |
| 117 |
* |
| 118 |
* This is raised when the server returns a non-JSON response. This |
| 119 |
* should only occur when there is a server or some type of connectivity |
| 120 |
* issue. |
| 121 |
* |
| 122 |
* @uses AWeberException |
| 123 |
* @package |
| 124 |
* @version $id$ |
| 125 |
*/ |
| 126 |
class AWeberResponseError extends AWeberException { |
| 127 |
|
| 128 |
public function __construct($uri) { |
| 129 |
$this->uri = $uri; |
| 130 |
parent::__construct("Request for {$uri} did not respond properly."); |
| 131 |
} |
| 132 |
|
| 133 |
} |
| 134 |
|