woocommerce/includes/class-wc-data-exception.php

69 lines
1.3 KiB
PHP
Raw Normal View History

2016-08-17 10:44:56 +00:00
<?php
/**
* WooCommerce Data Exception Class
*
* Extends Exception to provide additional data.
*
* @author WooThemes
* @category Core
* @package WooCommerce
* @since 2.7
2016-08-17 10:44:56 +00:00
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WC_Data_Exception class.
2016-08-17 10:44:56 +00:00
*/
class WC_Data_Exception extends Exception {
/**
* Sanitized error code.
*
* @var string
*/
2016-08-17 10:44:56 +00:00
protected $error_code;
/**
* Error extra data.
2016-08-17 10:44:56 +00:00
*
* @var array
*/
protected $error_data;
/**
* Setup exception.
2016-08-17 10:44:56 +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
*/
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
}
/**
* Returns the error code.
*
2016-08-17 10:44:56 +00:00
* @return string
*/
public function getErrorCode() {
return $this->error_code;
}
/**
* Returns error data.
*
* @return array
*/
public function getErrorData() {
return $this->error_data;
}
2016-08-17 10:44:56 +00:00
}