Attributes
4 weeks ago
Enums
2 months ago
Infrastructure
4 weeks ago
InputTypes
2 months ago
Interfaces
2 months ago
Mutations
2 months ago
Pagination
2 months ago
Queries
4 weeks ago
Scalars
2 months ago
Traits
2 months ago
Types
2 months ago
Utils
4 weeks ago
ApiException.php
2 months ago
ForbiddenException.php
4 weeks ago
InvalidTokenException.php
4 weeks ago
NotFoundException.php
4 weeks ago
UnauthorizedException.php
4 weeks ago
ValidationException.php
4 weeks ago
ApiException.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Api; |
| 6 | |
| 7 | /** |
| 8 | * Exception for API errors with error codes and extensions. |
| 9 | */ |
| 10 | class ApiException extends \RuntimeException { |
| 11 | /** |
| 12 | * Constructor. |
| 13 | * |
| 14 | * @param string $message The error message. |
| 15 | * @param string $error_code The machine-readable error code. |
| 16 | * @param array $extensions Additional error metadata. |
| 17 | * @param int $status_code The HTTP status code. |
| 18 | * @param ?\Throwable $previous The previous throwable for chaining. |
| 19 | */ |
| 20 | public function __construct( |
| 21 | string $message, |
| 22 | private readonly string $error_code = 'INTERNAL_ERROR', |
| 23 | private readonly array $extensions = array(), |
| 24 | int $status_code = 500, |
| 25 | ?\Throwable $previous = null, |
| 26 | ) { |
| 27 | parent::__construct( $message, $status_code, $previous ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get the machine-readable error code. |
| 32 | * |
| 33 | * @return string |
| 34 | */ |
| 35 | public function getErrorCode(): string { |
| 36 | return $this->error_code; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get the additional error metadata. |
| 41 | * |
| 42 | * @return array |
| 43 | */ |
| 44 | public function getExtensions(): array { |
| 45 | return $this->extensions; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get the HTTP status code. |
| 50 | * |
| 51 | * @return int |
| 52 | */ |
| 53 | public function getStatusCode(): int { |
| 54 | return $this->getCode(); |
| 55 | } |
| 56 | } |
| 57 |