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