-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a renderable exception for OAuth errors
- Loading branch information
1 parent
b83ca3c
commit b3d9f05
Showing
10 changed files
with
216 additions
and
181 deletions.
There are no files selected for viewing
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,42 @@ | ||
<?php | ||
|
||
namespace Laravel\Passport\Exceptions; | ||
|
||
use Exception; | ||
use Illuminate\Http\Response; | ||
use League\OAuth2\Server\Exception\OAuthServerException as LeagueException; | ||
|
||
class OAuthServerException extends Exception | ||
{ | ||
/** | ||
* The response to render. | ||
* | ||
* @var \Illuminate\Http\Response | ||
*/ | ||
protected $response; | ||
|
||
/** | ||
* Create a new OAuthServerException. | ||
* | ||
* @param LeagueException $e | ||
* @param Response $response | ||
* @return void | ||
*/ | ||
public function __construct(LeagueException $e, Response $response) | ||
{ | ||
parent::__construct($e->getMessage(), $e->getCode(), $e); | ||
|
||
$this->response = $response; | ||
} | ||
|
||
/** | ||
* Render the exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function render($request) | ||
{ | ||
return $this->response; | ||
} | ||
} |
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
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
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,32 @@ | ||
<?php | ||
|
||
namespace Laravel\Passport\Http\Controllers; | ||
|
||
use Zend\Diactoros\Response as Psr7Response; | ||
use Laravel\Passport\Exceptions\OAuthServerException; | ||
use League\OAuth2\Server\Exception\OAuthServerException as LeagueException; | ||
|
||
trait HandlesOAuthErrors | ||
{ | ||
use ConvertsPsrResponses; | ||
|
||
/** | ||
* Perform the given callback with exception handling. | ||
* | ||
* @param \Closure $callback | ||
* @return mixed | ||
* | ||
* @throws \Laravel\Passport\Exceptions\OAuthServerException | ||
*/ | ||
protected function withErrorHandling($callback) | ||
{ | ||
try { | ||
return $callback(); | ||
} catch (LeagueException $e) { | ||
throw new OAuthServerException( | ||
$e, | ||
$this->convertResponse($e->generateHttpResponse(new Psr7Response)) | ||
); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.