2016-08-17 10:44:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Data Exception Class
|
|
|
|
*
|
|
|
|
* Extends Exception to provide additional data.
|
|
|
|
*
|
2017-01-23 19:29:16 +00:00
|
|
|
* @author WooThemes
|
|
|
|
* @category Core
|
|
|
|
* @package WooCommerce
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0
|
2016-08-17 10:44:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-23 19:29:16 +00:00
|
|
|
* WC_Data_Exception class.
|
2016-08-17 10:44:56 +00:00
|
|
|
*/
|
|
|
|
class WC_Data_Exception extends Exception {
|
|
|
|
|
2017-01-23 19:29:16 +00:00
|
|
|
/**
|
|
|
|
* Sanitized error code.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-08-17 10:44:56 +00:00
|
|
|
protected $error_code;
|
|
|
|
|
|
|
|
/**
|
2017-01-23 19:29:16 +00:00
|
|
|
* Error extra data.
|
2016-08-17 10:44:56 +00:00
|
|
|
*
|
2017-01-23 19:29:16 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $error_data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup exception.
|
2016-08-17 10:44:56 +00:00
|
|
|
*
|
2017-01-23 19:29:16 +00:00
|
|
|
* @param string $code Machine-readable error code, e.g `woocommerce_invalid_product_id`.
|
|
|
|
* @param string $message User-friendly translated error message, e.g. 'Product ID is invalid'.
|
|
|
|
* @param int $http_status_code Proper HTTP status code to respond with, e.g. 400.
|
|
|
|
* @param array $data Extra error data.
|
2016-08-17 10:44:56 +00:00
|
|
|
*/
|
2017-01-23 19:29:16 +00:00
|
|
|
public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
|
|
|
|
$this->error_code = $code;
|
|
|
|
$this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
|
|
|
|
|
|
|
|
parent::__construct( $message, $http_status_code );
|
2016-08-17 10:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-23 19:29:16 +00:00
|
|
|
* Returns the error code.
|
|
|
|
*
|
2016-08-17 10:44:56 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getErrorCode() {
|
|
|
|
return $this->error_code;
|
|
|
|
}
|
2017-01-23 19:29:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns error data.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getErrorData() {
|
|
|
|
return $this->error_data;
|
|
|
|
}
|
2016-08-17 10:44:56 +00:00
|
|
|
}
|