-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathBadResponseException.php
More file actions
71 lines (59 loc) · 1.9 KB
/
BadResponseException.php
File metadata and controls
71 lines (59 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php declare(strict_types=1);
namespace MpApiClient\Exception;
use GuzzleHttp\Exception\BadResponseException as GuzzleBadResponseException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Throwable;
class BadResponseException extends MpApiException
{
/**
* @var ErrorCode[]
*/
private array $errorCodes;
/**
* @param string $message
* @param int $code
* @param Throwable|null $previous
* @param ErrorCode[] $errorCodes
*/
final private function __construct(string $message = '', int $code = 0, Throwable $previous = null, array $errorCodes = [])
{
parent::__construct($message, $code, $previous);
$this->errorCodes = $errorCodes;
}
/**
* @param string $message
* @param int $code
* @param GuzzleBadResponseException $previous
* @param array<int, array<string, mixed>> $errorCodes
* @return static
*/
public static function createFromGuzzle(string $message, int $code, GuzzleBadResponseException $previous, array $errorCodes = []): BadResponseException
{
return new static(
$message,
$code,
$previous,
array_map(fn(array $item): ErrorCode => ErrorCode::createFromApi($item), $errorCodes),
);
}
/**
* @return ErrorCode[]
*/
public function getErrorCodes(): array
{
return $this->errorCodes;
}
public function getRequest(): RequestInterface
{
/** @var GuzzleBadResponseException $previous */
$previous = $this->getPrevious();
return $previous->getRequest();
}
public function getResponse(): ResponseInterface
{
/** @var GuzzleBadResponseException $previous */
$previous = $this->getPrevious();
return $previous->getResponse();
}
}