give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Exceptions
/
ApiResponseException.php
give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Exceptions
Last commit date
Contracts
3 months ago
ApiResponseException.php
3 months ago
AuthenticationException.php
3 months ago
AuthorizationException.php
3 months ago
ClientErrorException.php
3 months ago
ConflictException.php
3 months ago
DecodingException.php
3 months ago
MissingAuthenticationException.php
3 months ago
NotFoundException.php
3 months ago
ServerErrorException.php
3 months ago
UnexpectedResponseException.php
3 months ago
ValidationException.php
3 months ago
ApiResponseException.php
73 lines
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Give\Vendors\LiquidWeb\LicensingApiClient\Exceptions; |
| 4 | |
| 5 | use Give\Vendors\LiquidWeb\LicensingApiClient\Exceptions\Contracts\ApiErrorExceptionInterface; |
| 6 | use Give\Vendors\Psr\Http\Message\ResponseInterface; |
| 7 | use RuntimeException; |
| 8 | |
| 9 | /** |
| 10 | * Base exception for HTTP error responses returned by the licensing API. |
| 11 | */ |
| 12 | class ApiResponseException extends RuntimeException implements ApiErrorExceptionInterface |
| 13 | { |
| 14 | private ResponseInterface $response; |
| 15 | |
| 16 | private int $statusCode; |
| 17 | |
| 18 | private string $errorCode; |
| 19 | |
| 20 | /** |
| 21 | * @var array<array-key, mixed>|null |
| 22 | */ |
| 23 | private ?array $errorPayload; |
| 24 | |
| 25 | /** |
| 26 | * @param array<array-key, mixed>|null $errorPayload |
| 27 | */ |
| 28 | public function __construct( |
| 29 | string $message, |
| 30 | ResponseInterface $response, |
| 31 | int $statusCode, |
| 32 | string $errorCode, |
| 33 | ?array $errorPayload = null |
| 34 | ) { |
| 35 | parent::__construct($message, $statusCode); |
| 36 | |
| 37 | $this->response = $response; |
| 38 | $this->statusCode = $statusCode; |
| 39 | $this->errorCode = $errorCode; |
| 40 | $this->errorPayload = $errorPayload; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the raw PSR-7 response that triggered the exception. |
| 45 | */ |
| 46 | public function getResponse(): ResponseInterface { |
| 47 | return $this->response; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the HTTP status code from the failed response. |
| 52 | */ |
| 53 | public function statusCode(): int { |
| 54 | return $this->statusCode; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns the normalized API error code. |
| 59 | */ |
| 60 | public function errorCode(): string { |
| 61 | return $this->errorCode; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the decoded error payload when the response body matched a known JSON error shape. |
| 66 | * |
| 67 | * @return array<array-key, mixed>|null |
| 68 | */ |
| 69 | public function errorPayload(): ?array { |
| 70 | return $this->errorPayload; |
| 71 | } |
| 72 | } |
| 73 |