aboutsummaryrefslogtreecommitdiffstats
path: root/library/oauth2-php/lib/OAuth2Exception.inc
diff options
context:
space:
mode:
authorFabio Comuni <fabrix.xm@gmail.com>2011-10-20 15:57:35 +0200
committerFabio Comuni <fabrix.xm@gmail.com>2011-10-20 15:57:35 +0200
commitb06588ffa1c925d0a008a34bf8fa5c316b964b87 (patch)
treee17dd8db74a6da2742011d87d48a305db7d11a31 /library/oauth2-php/lib/OAuth2Exception.inc
parentdf996a8b5ed2ac33c26a522d65eca6d6a4abe439 (diff)
downloadvolse-hubzilla-b06588ffa1c925d0a008a34bf8fa5c316b964b87.tar.gz
volse-hubzilla-b06588ffa1c925d0a008a34bf8fa5c316b964b87.tar.bz2
volse-hubzilla-b06588ffa1c925d0a008a34bf8fa5c316b964b87.zip
Initial work adding oauth to api
Diffstat (limited to 'library/oauth2-php/lib/OAuth2Exception.inc')
-rw-r--r--library/oauth2-php/lib/OAuth2Exception.inc85
1 files changed, 85 insertions, 0 deletions
diff --git a/library/oauth2-php/lib/OAuth2Exception.inc b/library/oauth2-php/lib/OAuth2Exception.inc
new file mode 100644
index 000000000..8dc046974
--- /dev/null
+++ b/library/oauth2-php/lib/OAuth2Exception.inc
@@ -0,0 +1,85 @@
+<?php
+
+/**
+ * OAuth2.0 draft v10 exception handling.
+ *
+ * @author Originally written by Naitik Shah <naitik@facebook.com>.
+ * @author Update to draft v10 by Edison Wong <hswong3i@pantarei-design.com>.
+ *
+ * @sa <a href="https://github.com/facebook/php-sdk">Facebook PHP SDK</a>.
+ */
+class OAuth2Exception extends Exception {
+
+ /**
+ * The result from the API server that represents the exception information.
+ */
+ protected $result;
+
+ /**
+ * Make a new API Exception with the given result.
+ *
+ * @param $result
+ * The result from the API server.
+ */
+ public function __construct($result) {
+ $this->result = $result;
+
+ $code = isset($result['code']) ? $result['code'] : 0;
+
+ if (isset($result['error'])) {
+ // OAuth 2.0 Draft 10 style
+ $message = $result['error'];
+ }
+ elseif (isset($result['message'])) {
+ // cURL style
+ $message = $result['message'];
+ }
+ else {
+ $message = 'Unknown Error. Check getResult()';
+ }
+
+ parent::__construct($message, $code);
+ }
+
+ /**
+ * Return the associated result object returned by the API server.
+ *
+ * @returns
+ * The result from the API server.
+ */
+ public function getResult() {
+ return $this->result;
+ }
+
+ /**
+ * Returns the associated type for the error. This will default to
+ * 'Exception' when a type is not available.
+ *
+ * @return
+ * The type for the error.
+ */
+ public function getType() {
+ if (isset($this->result['error'])) {
+ $message = $this->result['error'];
+ if (is_string($message)) {
+ // OAuth 2.0 Draft 10 style
+ return $message;
+ }
+ }
+ return 'Exception';
+ }
+
+ /**
+ * To make debugging easier.
+ *
+ * @returns
+ * The string representation of the error.
+ */
+ public function __toString() {
+ $str = $this->getType() . ': ';
+ if ($this->code != 0) {
+ $str .= $this->code . ': ';
+ }
+ return $str . $this->message;
+ }
+}