Skip to content

Commit edf0cd4

Browse files
committed
fix: use Symfony Response base class in exception handler and update tests
The respond() callback must accept Symfony's base Response (not just Illuminate\Http\Response) since redirect responses also pass through it. Return \$response unchanged for non-Inertia requests instead of null to avoid a null propagating through the cookie middleware. Update impersonation tests to expect /control-plane instead of /admin after the redirect fix.
1 parent a969c02 commit edf0cd4

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

bootstrap/app.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
use Illuminate\Foundation\Configuration\Exceptions;
1111
use Illuminate\Foundation\Configuration\Middleware;
1212
use Illuminate\Http\Request;
13-
use Illuminate\Http\Response;
1413
use Inertia\Inertia;
1514
use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
15+
use Symfony\Component\HttpFoundation\Response;
1616

1717
return Application::configure(basePath: dirname(__DIR__))
1818
->withRouting(
@@ -59,13 +59,17 @@
5959
__DIR__.'/../app/Domain/*/Listeners',
6060
])
6161
->withExceptions(function (Exceptions $exceptions): void {
62-
$exceptions->respond(function (Response $response, Throwable $e, Request $request): ?Response {
62+
$exceptions->respond(function (Response $response, Throwable $e, Request $request): Response {
63+
if (! $request->inertia()) {
64+
return $response;
65+
}
66+
6367
$status = $response->getStatusCode();
6468

6569
$handled = [400, 401, 403, 404, 405, 419, 429, 500, 503];
6670

67-
if (! in_array($status, $handled, true) || ! $request->inertia()) {
68-
return null;
71+
if (! in_array($status, $handled, true)) {
72+
return $response;
6973
}
7074

7175
return Inertia::render('Error', [

tests/Feature/AdminImpersonationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
// Now stop it
6363
$this->post('/impersonation/stop')
64-
->assertRedirect('/admin');
64+
->assertRedirect('/control-plane');
6565

6666
expect(session('impersonating_as'))->toBeNull()
6767
->and(session('original_admin_id'))->toBeNull()
@@ -71,7 +71,7 @@
7171
it('stop works even with no active impersonation session', function (): void {
7272
$this->actingAs($this->superAdmin)
7373
->post('/impersonation/stop')
74-
->assertRedirect('/admin');
74+
->assertRedirect('/control-plane');
7575
});
7676
});
7777

0 commit comments

Comments
 (0)