| 1 | <?php |
||
| 14 | class UsageException extends Exception { |
||
| 15 | |||
| 16 | private string $apiCode; |
||
|
|
|||
| 17 | |||
| 18 | private array $result = []; |
||
| 19 | |||
| 20 | private string $rawMessage; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @since 0.1 |
||
| 24 | * |
||
| 25 | * @param string $apiCode The API error code. |
||
| 26 | * @param string $message The API error message. |
||
| 27 | * @param array $result the result the exception was generated from |
||
| 28 | */ |
||
| 29 | public function __construct( $apiCode = '', $message = '', $result = [] ) { |
||
| 30 | $this->apiCode = $apiCode; |
||
| 31 | $this->result = $result; |
||
| 32 | $this->rawMessage = $message; |
||
| 33 | $message = 'Code: ' . $apiCode . PHP_EOL . |
||
| 34 | 'Message: ' . $message . PHP_EOL . |
||
| 35 | 'Result: ' . json_encode( $result ); |
||
| 36 | parent::__construct( $message, 0, null ); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @since 0.1 |
||
| 41 | */ |
||
| 42 | public function getApiCode(): string { |
||
| 43 | return $this->apiCode; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @since 0.3 |
||
| 48 | * |
||
| 49 | * @return mixed[] |
||
| 50 | */ |
||
| 51 | public function getApiResult(): array { |
||
| 52 | return $this->result; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @since 2.3.0 |
||
| 57 | */ |
||
| 58 | public function getRawMessage(): string { |
||
| 59 | return $this->rawMessage; |
||
| 60 | } |
||
| 61 | |||
| 62 | } |
||
| 63 |