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 weeks ago
StockAvailabilityException.php
2 years ago
TooManyInCartException.php
2 years ago
RouteException.php
62 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 | |
| 33 | // Only drop values the client cannot act on. `0` and `false` are meaningful here (e.g. a confirmed total of zero). |
| 34 | $this->additional_data = array_filter( |
| 35 | (array) $additional_data, |
| 36 | static function ( $value ) { |
| 37 | return null !== $value && '' !== $value && [] !== $value; |
| 38 | } |
| 39 | ); |
| 40 | |
| 41 | parent::__construct( $message, $http_status_code ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns the error code. |
| 46 | * |
| 47 | * @return string |
| 48 | */ |
| 49 | public function getErrorCode() { |
| 50 | return $this->error_code; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns additional error data. |
| 55 | * |
| 56 | * @return array |
| 57 | */ |
| 58 | public function getAdditionalData() { |
| 59 | return $this->additional_data; |
| 60 | } |
| 61 | } |
| 62 |