Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BorisTheTripper's avatar

rendering from `->withExceptions(...)`, why aren't shared props available?

I'm trying to implement an error boundary using the approach recommended in the docs:

https://inertiajs.com/error-handling

The code below runs inside of withExceptions in bootstrap/app.php.

$exceptions->respond(function (Response $response, Throwable $exception, Request $request) {
    $should_use_boundary = true;
    if ($should_use_boundary) {
        return Inertia::render('Error', ['status' => $response->getStatusCode()])
            ->toResponse($request)
            ->setStatusCode($response->getStatusCode());
    } elseif ($response->getStatusCode() === 419) {
        return back()->with([
            'message' => 'The page expired, please try again.',
        ]);
    }

    return $response;
});

I expected the status prop to be available alongside the shared props defined in HandleInertiaRequests.share. However, it seems that status is really all that's available to me from this error boundary. Why is that? Can this be changed?

0 likes
1 reply
BorisTheTripper's avatar

UPDATE: as per this GitHub issue comment, I've added the following two lines before Inertia::render:

Inertia::setRootView('app');
Inertia::share((new HandleInertiaRequests())->share($request));

These work fine, but only when I don't have any session values inside HandleInertiaRequests.share. If I share something like this, however...

    'message' => fn() => $request->session()->get('message'),

...it'll cause RuntimeException: Session store not set on request. Any idea for a workaround here, too?

Please or to participate in this conversation.