/includes/api/legacy/v2/class-wc-api-exception.php

  1. <?php 
  2. /** 
  3. * WooCommerce API Exception Class 
  4. * 
  5. * Extends Exception to provide additional data 
  6. * 
  7. * @author WooThemes 
  8. * @category API 
  9. * @package WooCommerce/API 
  10. * @since 2.2 
  11. */ 
  12.  
  13. if ( ! defined( 'ABSPATH' ) ) { 
  14. exit; // Exit if accessed directly 
  15.  
  16. class WC_API_Exception extends Exception { 
  17.  
  18. /** @var string sanitized error code */ 
  19. protected $error_code; 
  20.  
  21. /** 
  22. * Setup exception, requires 3 params: 
  23. * 
  24. * error code - machine-readable, e.g. `woocommerce_invalid_product_id` 
  25. * error message - friendly message, e.g. 'Product ID is invalid' 
  26. * http status code - proper HTTP status code to respond with, e.g. 400 
  27. * 
  28. * @since 2.2 
  29. * @param string $error_code 
  30. * @param string $error_message user-friendly translated error message 
  31. * @param int $http_status_code HTTP status code to respond with 
  32. */ 
  33. public function __construct( $error_code, $error_message, $http_status_code ) { 
  34. $this->error_code = $error_code; 
  35. parent::__construct( $error_message, $http_status_code ); 
  36.  
  37. /** 
  38. * Returns the error code 
  39. * 
  40. * @since 2.2 
  41. * @return string 
  42. */ 
  43. public function getErrorCode() { 
  44. return $this->error_code; 
.