diff --git a/bootstrap/app.php b/bootstrap/app.php index abff5dd70..7ef532204 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -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__)) @@ -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; diff --git a/tests/Feature/Passport/OAuthServerExceptionReportingTest.php b/tests/Feature/Passport/OAuthServerExceptionReportingTest.php new file mode 100644 index 000000000..6089fe391 --- /dev/null +++ b/tests/Feature/Passport/OAuthServerExceptionReportingTest.php @@ -0,0 +1,26 @@ +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(); +});