Lines
100.00%
16 / 16
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 3 | ||
| getRequestInfoString | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 2 | ||
| 5 | class Exception extends \Exception | |
| 6 | { | |
| 7 | /** | |
| 8 | * @var \Psr\Http\Message\ResponseInterface|null $response | |
| 9 | */ | |
| 10 | public ?\Psr\Http\Message\ResponseInterface $response = null; | |
| 11 | ||
| 12 | /** | |
| 13 | * @var \Psr\Http\Message\RequestInterface|null $request | |
| 14 | */ | |
| 15 | public ?\Psr\Http\Message\RequestInterface $request = null; | |
| 16 | ||
| 17 | /** | |
| 18 | * @var String $template for rendering exception | |
| 19 | * | |
| 20 | */ | |
| 21 | public $template = 'bo/zmsclient/exception'; | |
| 22 | ||
| 23 | /** | |
| 24 | * @var Mixed $data for rendering exception | |
| 25 | * | |
| 26 | */ | |
| 27 | public $data = []; | |
| 28 | ||
| 29 | /** | |
| 30 | * @var Mixed $trace Code trace | |
| 31 | * | |
| 32 | */ | |
| 33 | public $trace; | |
| 34 | ||
| 35 | /** | |
| 36 | * @var string|null $originalMessage | |
| 37 | */ | |
| 38 | public $originalMessage; | |
| 39 | ||
| 40 | /** | |
| 41 | * @var mixed $templatedata | |
| 42 | */ | |
| 43 | public mixed $templatedata = null; | |
| 44 | ||
| 45 | /** | |
| 46 | * @param String $message | |
| 47 | * @param \Psr\Http\Message\ResponseInterface $response | |
| 48 | * @param \Psr\Http\Message\RequestInterface $request (optional) reference for better error messages | |
| 49 | * @param \Exception $previous | |
| 50 | */ | |
| 51 | public function __construct( | |
| 52 | $message = '', | |
| 53 | ?\Psr\Http\Message\ResponseInterface $response = null, | |
| 54 | ?\Psr\Http\Message\RequestInterface $request = null, | |
| 55 | ?\Exception $previous = null | |
| 56 | ) { | |
| 57 | $this->response = $response; | |
| 58 | $this->request = $request; | |
| 59 | $code = $this->code; | |
| 60 | if (null !== $response) { | |
| 61 | $code = $response->getStatusCode(); | |
| 62 | } | |
| 63 | if (null !== $request) { | |
| 64 | $info = $this->getRequestInfoString(); | |
| 65 | $message .= " $info"; | |
| 66 | } | |
| 67 | parent::__construct($message, $code, $previous); | |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * Info about request intended for error messages | |
| 72 | * | |
| 73 | * @return string | |
| 74 | */ | |
| 75 | protected function getRequestInfoString() | |
| 76 | { | |
| 77 | $info = ''; | |
| 78 | if (null !== $this->request) { | |
| 79 | $uri = $this->request->getRequestTarget(); | |
| 80 | $protocol = $this->request->getProtocolVersion(); | |
| 81 | $method = $this->request->getMethod(); | |
| 82 | $info = "($method $uri HTTP/$protocol)"; | |
| 83 | } | |
| 84 | return $info; | |
| 85 | } | |
| 86 | } |