Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

fix: stop reporting client-error OAuth exceptions to Nightwatch (#261)

Paulo Castellano4be33d00d2d0
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\Exceptions;
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 @@ return Application::configure(basePath: dirname(__DIR__))
]);
})
->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 @@
+<?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();
+});