RequestException::getErrorCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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