1: <?php declare(strict_types=1);
2:
3: namespace Salient\Curler\Exception;
4:
5: use Psr\Http\Message\RequestInterface;
6: use Salient\Core\AbstractException;
7: use Salient\Http\HttpRequest;
8: use Salient\Utility\Format;
9: use Throwable;
10:
11: /**
12: * @api
13: */
14: abstract class AbstractRequestException extends AbstractException
15: {
16: protected RequestInterface $Request;
17: /** @var array<string,mixed> */
18: protected array $Data;
19:
20: /**
21: * @param array<string,mixed> $data
22: */
23: public function __construct(
24: string $message,
25: RequestInterface $request,
26: array $data = [],
27: ?Throwable $previous = null
28: ) {
29: $this->Request = $request;
30: $this->Data = $data;
31:
32: parent::__construct($message, $previous);
33: }
34:
35: /**
36: * @inheritDoc
37: */
38: public function getRequest(): RequestInterface
39: {
40: return $this->Request;
41: }
42:
43: /**
44: * @inheritDoc
45: */
46: public function getMetadata(): array
47: {
48: return [
49: 'Request' => (string) HttpRequest::fromPsr7($this->Request),
50: 'Data' => $this->Data
51: ? Format::array($this->Data)
52: : '<none>',
53: ];
54: }
55: }
56: