MonsterInsights_GA_Lib_Service_Exception

The Google Analytics for WordPress by MonsterInsights MonsterInsights GA Lib Service Exception class.

Defined (1)

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

/assets/lib/google/src/Google/Service/Exception.php  
  1. class MonsterInsights_GA_Lib_Service_Exception extends MonsterInsights_GA_Lib_Exception implements MonsterInsights_GA_Lib_Task_Retryable 
  2. /** 
  3. * Optional list of errors returned in a JSON body of an HTTP error response. 
  4. */ 
  5. protected $errors = array(); 
  6.  
  7. /** 
  8. * @var array $retryMap Map of errors with retry counts. 
  9. */ 
  10. private $retryMap = array(); 
  11.  
  12. /** 
  13. * Override default constructor to add the ability to set $errors and a retry 
  14. * map. 
  15. * @param string $message 
  16. * @param int $code 
  17. * @param Exception|null $previous 
  18. * @param [{string, string}] errors List of errors returned in an HTTP 
  19. * response. Defaults to []. 
  20. * @param array|null $retryMap Map of errors with retry counts. 
  21. */ 
  22. public function __construct( 
  23. $message,  
  24. $code = 0,  
  25. Exception $previous = null,  
  26. $errors = array(),  
  27. array $retryMap = null 
  28. ) { 
  29. if (version_compare(PHP_VERSION, '5.3.0') >= 0) { 
  30. parent::__construct($message, $code, $previous); 
  31. } else { 
  32. parent::__construct($message, $code); 
  33.  
  34. $this->errors = $errors; 
  35.  
  36. if (is_array($retryMap)) { 
  37. $this->retryMap = $retryMap; 
  38.  
  39. /** 
  40. * An example of the possible errors returned. 
  41. * { 
  42. * "domain": "global",  
  43. * "reason": "authError",  
  44. * "message": "Invalid Credentials",  
  45. * "locationType": "header",  
  46. * "location": "Authorization",  
  47. * } 
  48. * @return [{string, string}] List of errors return in an HTTP response or []. 
  49. */ 
  50. public function getErrors() 
  51. return $this->errors; 
  52.  
  53. /** 
  54. * Gets the number of times the associated task can be retried. 
  55. * NOTE: -1 is returned if the task can be retried indefinitely 
  56. * @return integer 
  57. */ 
  58. public function allowedRetries() 
  59. if (isset($this->retryMap[$this->code])) { 
  60. return $this->retryMap[$this->code]; 
  61.  
  62. $errors = $this->getErrors(); 
  63.  
  64. if (!empty($errors) && isset($errors[0]['reason']) && 
  65. isset($this->retryMap[$errors[0]['reason']])) { 
  66. return $this->retryMap[$errors[0]['reason']]; 
  67.  
  68. return 0;