Closed ToguyC closed 1 year ago
It all depends on whether the error occurs before or after any "share" middleware is executed.
Your solution seems fine, although you may want to increase the priority of your middleware.
I would be mindful of depending on a database query to succeed (retrieving the user) in your error-handling approach though.
Hi !
I am currently creating a project involving Inertia for the first time, and I came across a weir behavior. Indeed, I tried to create some custom HTTP error pages for 404, 501, etc., but I found out that my shared data setup in the
InertiaHandleRequest
middleware were not shared on error pages (see: https://inertiajs.com/error-handling for the backend implementation of error redirection).The data that I wanted to have globally no matter the state of the app was containing:
Those were never passed to my custom error view.
The workaround I found was to create a custom Laravel middleware called
SharedDataMiddleware
that share the most important data like auth, appName and locale, and register this middleware as a global middleware for all request no matter what kind.Is this a proper way to bypass the problem I have or is it not the recommended way ?
Please let me know if something is shady so I can fix my mistakes and continue with development.
Cheers.