ReserveStockException.php
61 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Exceptions for stock reservation. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Checkout\Helpers; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | /** |
| 11 | * ReserveStockException class. |
| 12 | */ |
| 13 | class ReserveStockException extends \Exception { |
| 14 | /** |
| 15 | * Sanitized error code. |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | protected $error_code; |
| 20 | |
| 21 | /** |
| 22 | * Error extra data. |
| 23 | * |
| 24 | * @var array |
| 25 | */ |
| 26 | protected $error_data; |
| 27 | |
| 28 | /** |
| 29 | * Setup exception. |
| 30 | * |
| 31 | * @param string $code Machine-readable error code, e.g `woocommerce_invalid_product_id`. |
| 32 | * @param string $message User-friendly translated error message, e.g. 'Product ID is invalid'. |
| 33 | * @param int $http_status_code Proper HTTP status code to respond with, e.g. 400. |
| 34 | * @param array $data Extra error data. |
| 35 | */ |
| 36 | public function __construct( $code, $message, $http_status_code = 400, $data = array() ) { |
| 37 | $this->error_code = $code; |
| 38 | $this->error_data = $data; |
| 39 | |
| 40 | parent::__construct( $message, $http_status_code ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the error code. |
| 45 | * |
| 46 | * @return string |
| 47 | */ |
| 48 | public function getErrorCode() { |
| 49 | return $this->error_code; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Returns error data. |
| 54 | * |
| 55 | * @return array |
| 56 | */ |
| 57 | public function getErrorData() { |
| 58 | return $this->error_data; |
| 59 | } |
| 60 | } |
| 61 |