1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of indragunawan/rest-service package. |
5
|
|
|
* |
6
|
|
|
* (c) Indra Gunawan <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace IndraGunawan\RestService\Exception; |
13
|
|
|
|
14
|
|
|
use GuzzleHttp\Exception\BadResponseException as BaseBadResponseException; |
15
|
|
|
use Psr\Http\Message\RequestInterface; |
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
17
|
|
|
|
18
|
|
|
class BadResponseException extends BaseBadResponseException |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var mixed |
22
|
|
|
*/ |
23
|
|
|
private $responseCode; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $responseMessage; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param mixed $responseCode |
32
|
|
|
* @param string $responseMessage |
33
|
|
|
* @param string $message |
34
|
|
|
* @param RequestInterface $request |
35
|
|
|
* @param ResponseInterface|null $response |
36
|
|
|
* @param \Exception|null $previous |
37
|
|
|
*/ |
38
|
2 |
|
public function __construct( |
39
|
|
|
$responseCode, |
40
|
|
|
$responseMessage, |
41
|
|
|
$message, |
42
|
|
|
RequestInterface $request, |
43
|
|
|
ResponseInterface $response = null, |
44
|
|
|
\Exception $previous = null |
45
|
|
|
) { |
46
|
2 |
|
$this->responseCode = $responseCode; |
47
|
2 |
|
$this->responseMessage = $responseMessage; |
48
|
|
|
|
49
|
2 |
|
parent::__construct($message, $request, $response, $previous); |
50
|
2 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get Status Code. |
54
|
|
|
* |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
1 |
|
public function getStatusCode() |
58
|
|
|
{ |
59
|
1 |
|
return $this->responseCode; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get Status Message. |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
1 |
|
public function getStatusMessage() |
68
|
|
|
{ |
69
|
1 |
|
return $this->responseMessage; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
1 |
|
public function __toString() |
76
|
|
|
{ |
77
|
1 |
|
return $this->responseCode.': '.$this->responseMessage; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|