aboutsummaryrefslogtreecommitdiff
path: root/vendor/tumblr/tumblr/lib/Tumblr/API/RequestException.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tumblr/tumblr/lib/Tumblr/API/RequestException.php')
-rw-r--r--vendor/tumblr/tumblr/lib/Tumblr/API/RequestException.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/tumblr/tumblr/lib/Tumblr/API/RequestException.php b/vendor/tumblr/tumblr/lib/Tumblr/API/RequestException.php
new file mode 100644
index 0000000..00af04b
--- /dev/null
+++ b/vendor/tumblr/tumblr/lib/Tumblr/API/RequestException.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Tumblr\API;
+
+class RequestException extends \Exception
+{
+
+ /**
+ * @param \stdClass $response
+ */
+ public function __construct($response)
+ {
+ $error = json_decode($response->body);
+
+ $errstr = 'Unknown Error';
+ if (isset($error->meta)) {
+ $errstr = $error->meta->msg;
+ if (isset($error->response->errors)) {
+ $errstr .= ' ('.$error->response->errors[0].')';
+ }
+ } elseif (isset($error->response->errors)) {
+ $errstr = $error->response->errors[0];
+ }
+
+ $this->statusCode = $response->status;
+ $this->message = $errstr;
+ parent::__construct($this->message, $this->statusCode);
+ }
+
+ public function __toString()
+ {
+ return __CLASS__ . ": [$this->statusCode]: $this->message\n";
+ }
+
+}