-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fc2a60
commit 0c8b940
Showing
2 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/Provider/Exception/GithubIdentityProviderException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Client\Provider\Exception; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class GithubIdentityProviderException extends IdentityProviderException | ||
{ | ||
/** | ||
* Creates client exception from response. | ||
* | ||
* @param ResponseInterface $response | ||
* @param string $data Parsed response data | ||
* | ||
* @return IdentityProviderException | ||
*/ | ||
public static function clientException(ResponseInterface $response, $data) | ||
{ | ||
return static::fromResponse( | ||
$response, | ||
isset($data['message']) ? $data['message'] : $response->getReasonPhrase() | ||
); | ||
} | ||
|
||
/** | ||
* Creates oauth exception from response. | ||
* | ||
* @param ResponseInterface $response | ||
* @param string $data Parsed response data | ||
* | ||
* @return IdentityProviderException | ||
*/ | ||
public static function oauthException(ResponseInterface $response, $data) | ||
{ | ||
return static::fromResponse( | ||
$response, | ||
isset($data['error']) ? $data['error'] : $response->getReasonPhrase() | ||
); | ||
} | ||
|
||
/** | ||
* Creates identity exception from response. | ||
* | ||
* @param ResponseInterface $response | ||
* @param string $message | ||
* | ||
* @return IdentityProviderException | ||
*/ | ||
protected static function fromResponse(ResponseInterface $response, $message = null) | ||
{ | ||
return new static($message, $response->getStatusCode(), (string) $response->getBody()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters