for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace LucaDegasperi\OAuth2Server\Middleware;
use Closure;
use Illuminate\Http\JsonResponse;
use League\OAuth2\Server\Exception\OAuthException;
/**
* This is the exception handler middleware class.
* @author Luca Degasperi <[email protected]>
class OAuthExceptionHandlerMiddleware
{
* Handle an incoming request.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
public function handle($request, Closure $next)
$response = $next($request);
// Was an OAuthException previously caught by the pipeline? If so, hijack response, replacing with json error.
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.
if (isset($response->exception) && $response->exception instanceof OAuthException) {
$data = [
'error' => $response->exception->errorType,
'error_description' => $response->exception->getMessage(),
];
return new JsonResponse($data, $response->exception->httpStatusCode, $response->exception->getHttpHeaders());
}
return $response;
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.