| 1 | <?php |
||
| 16 | class GeneralException extends \Exception { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Internal Error |
||
| 20 | */ |
||
| 21 | const ERROR_INTERNAL_ERROR = 'INTERNAL_ERROR'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Error code. |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $casCode; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Exception constructor. |
||
| 31 | * |
||
| 32 | * @param string $message Exception message. |
||
| 33 | * @param string $casCode CAS error code (default: "INTERNAL_ERROR"). |
||
| 34 | */ |
||
| 35 | public function __construct( $message = '', $casCode = self::ERROR_INTERNAL_ERROR ) { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Generate a new exception instance from a WordPress error. |
||
| 43 | * |
||
| 44 | * @param \WP_Error $error WordPress error. |
||
| 45 | * @return GeneralException WordPress error as an exception. |
||
| 46 | */ |
||
| 47 | public static function fromError( \WP_Error $error ) { |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Error code getter. |
||
| 55 | * |
||
| 56 | * @return string Associated error code. |
||
| 57 | */ |
||
| 58 | final public function getCASCode() { |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Returns a WordPress error object based on the exception. |
||
| 64 | * |
||
| 65 | * @return \WP_Error WordPress error. |
||
| 66 | */ |
||
| 67 | public function getErrorInstance() { |
||
| 70 | |||
| 71 | } |
||
| 72 |