Completed
Pull Request — master (#10)
by
unknown
02:57
created

RequestException::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
cc 4
eloc 12
nc 3
nop 2
1
<?php
2
3
namespace Akeneo\SalesForce\Exception;
4
5
class RequestException extends \Exception
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $errorCode;
11
12
    /**
13
     * @var string
14
     */
15
    private $requestBody;
16
17
    /**
18
     * @param string $message
19
     * @param string $requestBody
20
     */
21
    public function __construct($message, $requestBody)
22
    {
23
        $this->requestBody = $requestBody;
24
        $error             = json_decode($requestBody, true);
25
26
        //Errors generated during the auth stage are different to those generated during normal requests
27
        if (isset($error['error']) && isset($error['error_description'])) {
28
            $this->errorCode = $error['error'];
29
            parent::__construct($error['error_description']);
30
        } elseif (isset($error[0]['message'])) {
31
            $this->errorCode = $error[0]['errorCode'];
32
            parent::__construct($error[0]['message']);
33
        } else {
34
            $this->errorCode = $error['errorCode'];
35
            parent::__construct($error['message']);
36
        }
37
    }
38
39
    /**
40
     * @return mixed
41
     */
42
    public function getRequestBody()
43
    {
44
        return $this->requestBody;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getErrorCode()
51
    {
52
        return $this->errorCode;
53
    }
54
}
55