Passed
Push — master ( 5319ee...e6b641 )
by Dani
02:13
created

GraphQLException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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