oauth2-client/src/Exception/IDPException.php

60 lines
1.2 KiB
PHP
Raw Normal View History

2013-02-25 16:15:46 +04:00
<?php
2013-05-28 14:00:24 +04:00
namespace League\OAuth2\Client\Exception;
2013-02-25 16:15:46 +04:00
class IDPException extends \Exception
{
protected $result;
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);
2013-02-25 16:15:46 +04:00
}
public function getType()
{
2014-12-01 23:42:43 +03:00
$result = 'Exception';
2013-02-25 16:15:46 +04:00
if (isset($this->result['error'])) {
$message = $this->result['error'];
if (is_string($message)) {
// OAuth 2.0 Draft 10 style
2014-12-01 23:42:43 +03:00
$result = $message;
2013-02-25 16:15:46 +04:00
}
}
2014-12-01 23:42:43 +03:00
return $result;
2013-02-25 16:15:46 +04:00
}
/**
* To make debugging easier.
*
2014-02-02 02:59:40 +04:00
* @return string The string representation of the error.
2013-02-25 16:15:46 +04:00
*/
public function __toString()
{
2014-11-09 00:30:40 +03:00
$str = $this->getType().': ';
2013-02-25 16:15:46 +04:00
if ($this->code != 0) {
2014-11-09 00:30:40 +03:00
$str .= $this->code.': ';
2013-02-25 16:15:46 +04:00
}
2014-11-09 00:30:40 +03:00
return $str.$this->message;
2013-02-25 16:15:46 +04:00
}
}