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