1 | <?php |
||
2 | |||
3 | namespace Postpay\Exceptions; |
||
4 | |||
5 | use Postpay\Http\Response; |
||
6 | |||
7 | class GraphQLException extends ApiException |
||
8 | { |
||
9 | /** |
||
10 | * @const string Error key returned. |
||
11 | */ |
||
12 | const ERROR_KEY = 'errors'; |
||
13 | |||
14 | /** |
||
15 | * @var array The decoded JSON response errors. |
||
16 | */ |
||
17 | protected $errors = []; |
||
18 | |||
19 | /** |
||
20 | * Creates a RESTfulException. |
||
21 | * |
||
22 | * @param Response $response The response that threw the exception. |
||
23 | */ |
||
24 | 1 | public function __construct(Response $response) |
|
25 | { |
||
26 | 1 | $this->response = $response; |
|
27 | 1 | $this->decodedBody = $response->json(); |
|
28 | 1 | $this->errors = $this->decodedBody[self::ERROR_KEY]; |
|
29 | 1 | parent::__construct('GraphQL Error.'); |
|
30 | 1 | } |
|
31 | |||
32 | /** |
||
33 | * Return the JSON response errors. |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | 1 | public function getErrors() |
|
38 | { |
||
39 | 1 | return $this->errors; |
|
40 | } |
||
41 | } |
||
42 |