summaryrefslogtreecommitdiff
path: root/vendor/league/oauth2-client/src/Exception/IDPException.php
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2019-11-17 20:45:02 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2019-11-17 20:45:02 +0100
commit8df3db566a3a937b45ebf11adb90d265e6f5e2d4 (patch)
tree4d541098d751d5a9acf8c12f6fb9f308ace066ac /vendor/league/oauth2-client/src/Exception/IDPException.php
downloadflyspray-8df3db566a3a937b45ebf11adb90d265e6f5e2d4.tar.xz
initial checking of customized version 1.0rc9
Diffstat (limited to 'vendor/league/oauth2-client/src/Exception/IDPException.php')
-rw-r--r--vendor/league/oauth2-client/src/Exception/IDPException.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/vendor/league/oauth2-client/src/Exception/IDPException.php b/vendor/league/oauth2-client/src/Exception/IDPException.php
new file mode 100644
index 0000000..668a7e7
--- /dev/null
+++ b/vendor/league/oauth2-client/src/Exception/IDPException.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace League\OAuth2\Client\Exception;
+
+class IDPException extends \Exception
+{
+ protected $result;
+
+ public function __construct($result)
+ {
+ if (!empty($result['error']) && is_array($result['error'])) {
+ // Error response is wrapped in a top entity type, JSON:API style.
+ $result = $result['error'];
+ }
+
+ $this->result = $result;
+
+ $code = isset($result['code']) ? $result['code'] : 0;
+
+ if (isset($result['error']) && $result['error'] !== '') {
+ // OAuth 2.0 Draft 10 style
+ $message = $result['error'];
+ } elseif (isset($result['message']) && $result['message'] !== '') {
+ // cURL style
+ $message = $result['message'];
+ } else {
+ $message = 'Unknown Error.';
+ }
+
+ parent::__construct($message, $code);
+ }
+
+ public function getResponseBody()
+ {
+ return $this->result;
+ }
+
+ public function getType()
+ {
+ $result = 'Exception';
+
+ if (isset($this->result['error'])) {
+ $message = $this->result['error'];
+
+ if (is_string($message)) {
+ // OAuth 2.0 Draft 10 style
+ $result = $message;
+ }
+ }
+
+ return $result;
+ }
+
+ /**
+ * To make debugging easier.
+ *
+ * @return string The string representation of the error.
+ */
+ public function __toString()
+ {
+ $str = $this->getType().': ';
+
+ if ($this->code != 0) {
+ $str .= $this->code.': ';
+ }
+
+ return $str.$this->message;
+ }
+}