Add WC_API_Exception class

Part of #4160
This commit is contained in:
Max Rice 2014-07-27 23:20:48 -04:00
parent 95aab694e4
commit c9342d6344
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,48 @@
<?php
/**
* WooCommerce API Exception Class
*
* Extends Exception to provide additional data
*
* @author WooThemes
* @category API
* @package WooCommerce/API
* @since 2.2
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WC_API_Exception extends Exception {
/** @var string sanitized error code */
protected $error_code;
/**
* Setup exception, requires 3 params:
*
* error code - machine-readable, e.g. `woocommerce_invalid_product_id`
* error message - friendly message, e.g. 'Product ID is invalid'
* http status code - proper HTTP status code to respond with, e.g. 400
*
* @since 2.2
* @param string $error_code
* @param string $error_message user-friendly translated error message
* @param int $http_status_code HTTP status code to respond with
*/
public function __construct( $error_code, $error_message, $http_status_code ) {
$this->error_code = $error_code;
return parent::__construct( $error_message, $http_status_code );
}
/**
* Returns the error code
*
* @since 2.2
* @return string
*/
public function getErrorCode() {
return $this->error_code;
}
}

View File

@ -139,6 +139,7 @@ class WC_API {
private function includes() {
// API server / response handlers
include_once( 'api/class-wc-api-exception.php' );
include_once( 'api/class-wc-api-server.php' );
include_once( 'api/interface-wc-api-handler.php' );
include_once( 'api/class-wc-api-json-handler.php' );