Freemius_Exception

Thrown when an API call returns an exception.

Defined (1)

The class is defined in the following location(s).

/freemius/includes/sdk/Exceptions/Exception.php  
  1. class Freemius_Exception extends Exception { 
  2. protected $_result; 
  3. protected $_type; 
  4. protected $_code; 
  5.  
  6. /** 
  7. * Make a new API Exception with the given result. 
  8. * @param array $result The result from the API server. 
  9. */ 
  10. public function __construct( $result ) { 
  11. $this->_result = $result; 
  12.  
  13. $code = 0; 
  14. $message = 'Unknown error, please check GetResult().'; 
  15. $type = ''; 
  16.  
  17. if ( isset( $result['error'] ) && is_array( $result['error'] ) ) { 
  18. if ( isset( $result['error']['code'] ) ) { 
  19. $code = $result['error']['code']; 
  20. if ( isset( $result['error']['message'] ) ) { 
  21. $message = $result['error']['message']; 
  22. if ( isset( $result['error']['type'] ) ) { 
  23. $type = $result['error']['type']; 
  24.  
  25. $this->_type = $type; 
  26. $this->_code = $code; 
  27.  
  28. parent::__construct( $message, is_numeric( $code ) ? $code : 0 ); 
  29.  
  30. /** 
  31. * Return the associated result object returned by the API server. 
  32. * @return array The result from the API server 
  33. */ 
  34. public function getResult() { 
  35. return $this->_result; 
  36.  
  37. public function getStringCode() { 
  38. return $this->_code; 
  39.  
  40. public function getType() { 
  41. return $this->_type; 
  42.  
  43. /** 
  44. * To make debugging easier. 
  45. * @return string The string representation of the error 
  46. */ 
  47. public function __toString() { 
  48. $str = $this->getType() . ': '; 
  49.  
  50. if ( $this->code != 0 ) { 
  51. $str .= $this->getStringCode() . ': '; 
  52.  
  53. return $str . $this->getMessage();