1 | <?php |
||
4 | class MnsException extends \RuntimeException |
||
5 | { |
||
6 | private $mnsErrorCode; |
||
7 | private $requestId; |
||
8 | private $hostId; |
||
9 | |||
10 | public function __construct($code, $message, $previousException = NULL, $mnsErrorCode = NULL, $requestId = NULL, $hostId = NULL) |
||
11 | { |
||
12 | parent::__construct($message, $code, $previousException); |
||
13 | |||
14 | if ($mnsErrorCode == NULL) |
||
15 | { |
||
16 | if ($code >= 500) |
||
17 | { |
||
18 | $mnsErrorCode = "ServerError"; |
||
19 | } |
||
20 | else |
||
21 | { |
||
22 | $mnsErrorCode = "ClientError"; |
||
23 | } |
||
24 | } |
||
25 | $this->mnsErrorCode = $mnsErrorCode; |
||
26 | |||
27 | $this->requestId = $requestId; |
||
28 | $this->hostId = $hostId; |
||
29 | } |
||
30 | |||
31 | public function __toString() |
||
32 | { |
||
33 | $str = "Code: " . $this->getCode() . " Message: " . $this->getMessage(); |
||
34 | if ($this->mnsErrorCode != NULL) |
||
35 | { |
||
36 | $str .= " MnsErrorCode: " . $this->mnsErrorCode; |
||
37 | } |
||
38 | if ($this->requestId != NULL) |
||
39 | { |
||
40 | $str .= " RequestId: " . $this->requestId; |
||
41 | } |
||
42 | if ($this->hostId != NULL) |
||
43 | { |
||
44 | $str .= " HostId: " . $this->hostId; |
||
45 | } |
||
46 | return $str; |
||
47 | } |
||
48 | |||
49 | public function getMnsErrorCode() |
||
50 | { |
||
51 | return $this->mnsErrorCode; |
||
52 | } |
||
53 | |||
54 | public function getRequestId() |
||
55 | { |
||
56 | return $this->requestId; |
||
57 | } |
||
58 | |||
59 | public function getHostId() |
||
60 | { |
||
61 | return $this->hostId; |
||
62 | } |
||
63 | } |
||
64 | |||
66 |