Total Complexity | 9 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Coverage | 95.45% |
Changes | 0 |
1 | <?php |
||
12 | class RequestException extends \Exception implements RequestExceptionInterface |
||
13 | { |
||
14 | protected $responseCode; |
||
15 | |||
16 | protected $message; |
||
17 | |||
18 | protected $type; |
||
19 | |||
20 | /** |
||
21 | * Request exception constructor |
||
22 | * |
||
23 | * @param string $response json_decoded array with the error response given by the server |
||
24 | */ |
||
25 | 4 | public function __construct($response) |
|
26 | { |
||
27 | 4 | $message = ''; |
|
28 | 4 | $code = null; |
|
29 | 4 | $type = null; |
|
30 | 4 | if (is_string($response)) { |
|
|
|||
31 | $message = $response; |
||
32 | 4 | } elseif (is_array($response)) { |
|
33 | 4 | $error = isset($response['error']) ? $response['error'] : ''; |
|
34 | 4 | if (isset($error['code'])) { |
|
35 | 4 | $code = $error['code']; |
|
36 | } |
||
37 | 4 | if (isset($error['message'])) { |
|
38 | 4 | $message = $error['message']; |
|
39 | } |
||
40 | 4 | if (isset($error['type'])) { |
|
41 | 4 | $type = $error['type']; |
|
42 | } |
||
43 | } |
||
44 | |||
45 | 4 | $this->responseCode = $code; |
|
46 | 4 | $this->type = $type; |
|
47 | 4 | parent::__construct($message, $code); |
|
48 | 4 | } |
|
49 | |||
50 | /** |
||
51 | * @inheritdoc |
||
52 | */ |
||
53 | 1 | public function getResponseCode() |
|
54 | { |
||
55 | 1 | return $this->responseCode; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * @inheritdoc |
||
60 | */ |
||
61 | 1 | public function getType() |
|
64 | } |
||
65 | } |
||
66 |