InvalidCartException.php
2 years ago
InvalidStockLevelsInCartException.php
2 years ago
NotPurchasableException.php
2 years ago
OutOfStockException.php
2 years ago
PartialOutOfStockException.php
2 years ago
RouteException.php
2 years ago
StockAvailabilityException.php
2 years ago
TooManyInCartException.php
2 years ago
RouteException.php
54 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\StoreApi\Exceptions; |
| 3 | |
| 4 | /** |
| 5 | * RouteException class. |
| 6 | */ |
| 7 | class RouteException extends \Exception { |
| 8 | /** |
| 9 | * Sanitized error code. |
| 10 | * |
| 11 | * @var string |
| 12 | */ |
| 13 | public $error_code; |
| 14 | |
| 15 | /** |
| 16 | * Additional error data. |
| 17 | * |
| 18 | * @var array |
| 19 | */ |
| 20 | public $additional_data = []; |
| 21 | |
| 22 | /** |
| 23 | * Setup exception. |
| 24 | * |
| 25 | * @param string $error_code Machine-readable error code, e.g `woocommerce_invalid_product_id`. |
| 26 | * @param string $message User-friendly translated error message, e.g. 'Product ID is invalid'. |
| 27 | * @param int $http_status_code Proper HTTP status code to respond with, e.g. 400. |
| 28 | * @param array $additional_data Extra data (key value pairs) to expose in the error response. |
| 29 | */ |
| 30 | public function __construct( $error_code, $message, $http_status_code = 400, $additional_data = [] ) { |
| 31 | $this->error_code = $error_code; |
| 32 | $this->additional_data = array_filter( (array) $additional_data ); |
| 33 | parent::__construct( $message, $http_status_code ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns the error code. |
| 38 | * |
| 39 | * @return string |
| 40 | */ |
| 41 | public function getErrorCode() { |
| 42 | return $this->error_code; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns additional error data. |
| 47 | * |
| 48 | * @return array |
| 49 | */ |
| 50 | public function getAdditionalData() { |
| 51 | return $this->additional_data; |
| 52 | } |
| 53 | } |
| 54 |