forked from philsturgeon/codeigniter-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOAuth2_Exception.php
45 lines (39 loc) · 899 Bytes
/
OAuth2_Exception.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?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>.
*/
class OAuth2_Exception 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.';
}
parent::__construct($message, $code);
}
}