Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
use Illuminate\Http\Request;
use League\OAuth2\Server\Exception\OAuthServerException;
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;

return Application::configure(basePath: dirname(__DIR__))
Expand Down Expand Up @@ -44,6 +45,10 @@
]);
})
->withExceptions(function (Exceptions $exceptions): void {
$exceptions->dontReportWhen(function (Throwable $e) {
return $e instanceof OAuthServerException && $e->getHttpStatusCode() < 500;
});

$exceptions->renderable(function (TooManyRequestsHttpException $e, Request $request) {
if ($request->expectsJson()) {
$retryAfter = $e->getHeaders()['Retry-After'] ?? null;
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/Passport/OAuthServerExceptionReportingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Illuminate\Contracts\Debug\ExceptionHandler;
use League\OAuth2\Server\Exception\OAuthServerException;

test('client-error oauth exceptions are not reported', function () {
$handler = app(ExceptionHandler::class);

expect($handler->shouldReport(OAuthServerException::accessDenied()))->toBeFalse()
->and($handler->shouldReport(OAuthServerException::invalidGrant()))->toBeFalse()
->and($handler->shouldReport(OAuthServerException::invalidRequest('grant_type')))->toBeFalse();
});

test('server-error oauth exceptions are still reported', function () {
$handler = app(ExceptionHandler::class);

expect($handler->shouldReport(OAuthServerException::serverError('unexpected failure')))->toBeTrue();
});

test('unrelated exceptions are unaffected', function () {
$handler = app(ExceptionHandler::class);

expect($handler->shouldReport(new RuntimeException('boom')))->toBeTrue();
});