Comments (6)
I guess we could do something like this:
public function render($request, Exception $exception)
{
return Inertia::renderErrorResponse(
string $component,
Response $response,
array $codes
);
}
For example:
public function render($request, Exception $exception)
{
return Inertia::renderErrorResponse(
'Error',
parent::render($request, $exception),
[500, 503, 404, 403]
);
}
Again, not sure that this is worth adding to the framework, since it really doesn't require that much code to just do this yourself.
from inertia-laravel.
I just updated the docs with a pretty straight forward solution:
use Inertia\Inertia;
public function render($request, Exception $exception)
{
$response = parent::render($request, $exception);
if ($request->header('X-Inertia') && in_array($response->status(), [500, 503, 404, 403])) {
return Inertia::render('Error', ['status' => $response->status()])
->toResponse($request)
->setStatusCode($response->status());
}
return $response;
}
Basically I decided it was an act of futility to try and figure out every possible exception that could get thrown. Instead, I just let Laravel generate the correct Response
, and I use that decide whether I want to show an Inertia error page.
A corresponding error page component could look like this:
<template>
<div>
<h1>{{ title }}</h1>
<div>{{ description }}</div>
</div>
</template>
<script>
export default {
props: {
status: Number,
},
computed: {
title() {
return {
503: '503: Service Unavailable',
500: '500: Server Error',
404: '404: Page Not Found',
403: '404: Forbidden',
}[this.status]
},
description() {
return {
503: 'Sorry, we are doing some maintenance. Please check back soon.',
500: 'Whoops, something went wrong on our servers.',
404: 'Sorry, the page you are looking for could not be found.',
403: 'Sorry, you are forbidden from accessing this page.',
}[this.status]
},
},
}
</script>
This gives developers tons of flexibility to create their own custom designed error pages.
I'm kind of happy with this as a final solution. I'm not sure this library needs to do anything more...although I'm still open to it.
from inertia-laravel.
Closing this, because I think the above solution is actually perfect. π
from inertia-laravel.
I've implemented the solution outlined in the docs, but anytime I run into a 403, it's still showing laravel's stubbed 403 page... Any ideas why this might be happening?
from inertia-laravel.
Never mind... π€¦ I was testing locally so I got rid of the !app()->environment(['local', 'testing'])
condition and I can see everything now...
from inertia-laravel.
Hello!
I have gotten an error when taking my app to production in a shared hosting (cpanel).
The error is that when I try to render a view, it does not render as such, but instead displays the data coming from the controller in a modal.
How can I solve this?
Thank you.
from inertia-laravel.
Related Issues (20)
- Login not working with Laravel + Inertia + React HOT 1
- problem in running ssr when using vue vite and ziggy
- Add dinamic parameters to Inertia::lazyLoad props HOT 1
- SSR with Dynamically Shared Props HOT 1
- Providing empty object to the view
- Add config option to ignore paths with SSR server HOT 1
- Progress bar not working on route navigation HOT 1
- Laravel / Vue 3 Install Issues HOT 1
- Inertia with Laravel + SSR + pm2 HOT 1
- Laravel Inertia Form Validation Issue
- Safari can not handle redirect()->back() HOT 1
- Router events runs multiple times. HOT 5
- JSON response error on subdomains - Firefox HOT 1
- Inertia with supervisor SSR error HOT 1
- SSR (react) error ui doesn't match initial ui when including prop having html
- β¨Feature Request: Support `ziggy` 2.0 HOT 4
- fails testing nested pros
- External JS files not working unless you manually reload the page HOT 1
- image upload help HOT 2
- Laravel 11 support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inertia-laravel.