exceptions.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. class AWeberException extends Exception { }
  3. /**
  4. * Thrown when the API returns an error. (HTTP status >= 400)
  5. *
  6. *
  7. * @uses AWeberException
  8. * @package
  9. * @version $id$
  10. */
  11. class AWeberAPIException extends AWeberException {
  12. public $type;
  13. public $status;
  14. public $message;
  15. public $documentation_url;
  16. public $url;
  17. public function __construct($error, $url) {
  18. // record specific details of the API exception for processing
  19. $this->url = $url;
  20. $this->type = $error['type'];
  21. $this->status = array_key_exists('status', $error) ? $error['status'] : '';
  22. $this->message = $error['message'];
  23. $this->documentation_url = $error['documentation_url'];
  24. parent::__construct($this->message);
  25. }
  26. }
  27. /**
  28. * Thrown when attempting to use a resource that is not implemented.
  29. *
  30. * @uses AWeberException
  31. * @package
  32. * @version $id$
  33. */
  34. class AWeberResourceNotImplemented extends AWeberException {
  35. public function __construct($object, $value) {
  36. $this->object = $object;
  37. $this->value = $value;
  38. parent::__construct("Resource \"{$value}\" is not implemented on this resource.");
  39. }
  40. }
  41. /**
  42. * AWeberMethodNotImplemented
  43. *
  44. * Thrown when attempting to call a method that is not implemented for a resource
  45. * / collection. Differs from standard method not defined errors, as this will
  46. * be thrown when the method is infact implemented on the base class, but the
  47. * current resource type does not provide access to that method (ie calling
  48. * getByMessageNumber on a web_forms collection).
  49. *
  50. * @uses AWeberException
  51. * @package
  52. * @version $id$
  53. */
  54. class AWeberMethodNotImplemented extends AWeberException {
  55. public function __construct($object) {
  56. $this->object = $object;
  57. parent::__construct("This method is not implemented by the current resource.");
  58. }
  59. }
  60. /**
  61. * AWeberOAuthException
  62. *
  63. * OAuth exception, as generated by an API JSON error response
  64. * @uses AWeberException
  65. * @package
  66. * @version $id$
  67. */
  68. class AWeberOAuthException extends AWeberException {
  69. public function __construct($type, $message) {
  70. $this->type = $type;
  71. $this->message = $message;
  72. parent::__construct("{$type}: {$message}");
  73. }
  74. }
  75. /**
  76. * AWeberOAuthDataMissing
  77. *
  78. * Used when a specific piece or pieces of data was not found in the
  79. * response. This differs from the exception that might be thrown as
  80. * an AWeberOAuthException when parameters are not provided because
  81. * it is not the servers' expectations that were not met, but rather
  82. * the expecations of the client were not met by the server.
  83. *
  84. * @uses AWeberException
  85. * @package
  86. * @version $id$
  87. */
  88. class AWeberOAuthDataMissing extends AWeberException {
  89. public function __construct($missing) {
  90. if (!is_array($missing)) $missing = array($missing);
  91. $this->missing = $missing;
  92. $required = join(', ', $this->missing);
  93. parent::__construct("OAuthDataMissing: Response was expected to contain: {$required}");
  94. }
  95. }
  96. /**
  97. * AWeberResponseError
  98. *
  99. * This is raised when the server returns a non-JSON response. This
  100. * should only occur when there is a server or some type of connectivity
  101. * issue.
  102. *
  103. * @uses AWeberException
  104. * @package
  105. * @version $id$
  106. */
  107. class AWeberResponseError extends AWeberException {
  108. public function __construct($uri) {
  109. $this->uri = $uri;
  110. parent::__construct("Request for {$uri} did not respond properly.");
  111. }
  112. }