Skip to content

Commit 44e6ea0

Browse files
committed
Error page
1 parent eade04b commit 44e6ea0

File tree

2 files changed

+87
-65
lines changed

2 files changed

+87
-65
lines changed

bootstrap/app.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<?php
22

3+
use App\Http\Middleware\HandleInertiaRequests;
34
use Illuminate\Foundation\Application;
45
use Illuminate\Foundation\Configuration\Exceptions;
56
use Illuminate\Foundation\Configuration\Middleware;
7+
use Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets;
8+
use Illuminate\Http\Request;
9+
use Inertia\Inertia;
10+
use Symfony\Component\HttpFoundation\Response;
611

712
return Application::configure(basePath: dirname(__DIR__))
813
->withRouting(
@@ -12,12 +17,28 @@
1217
)
1318
->withMiddleware(function (Middleware $middleware) {
1419
$middleware->web(append: [
15-
App\Http\Middleware\HandleInertiaRequests::class,
16-
Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
20+
HandleInertiaRequests::class,
21+
AddLinkHeadersForPreloadedAssets::class,
1722
]);
18-
19-
//
2023
})
2124
->withExceptions(function (Exceptions $exceptions) {
22-
//
25+
$exceptions->respond(function (Response $response, Throwable $exception, Request $request) {
26+
if (
27+
!app()->environment(['local', 'testing'])
28+
&& in_array($response->getStatusCode(), [500, 503, 404, 403])
29+
) {
30+
return Inertia::render('Error', [
31+
'homepageRoute' => route('welcome'),
32+
'status' => $response->getStatusCode()
33+
])
34+
->toResponse($request)
35+
->setStatusCode($response->getStatusCode());
36+
} elseif ($response->getStatusCode() === 419) {
37+
return back()->with([
38+
'message' => 'The page expired, please try again.',
39+
]);
40+
}
41+
42+
return $response;
43+
});
2344
})->create();

resources/js/pages/Error.vue

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,62 @@
1-
<script setup>
2-
import { computed } from 'vue';
3-
import { ArrowLeft } from 'lucide-vue-next';
4-
5-
const props = defineProps({
6-
homeRoute: String,
7-
status: Number
8-
});
9-
10-
const title = computed(() => {
11-
return {
12-
503: '503: Service Unavailable',
13-
500: '500: Server Error',
14-
404: '404: Page Not Found',
15-
403: '403: Forbidden',
16-
}[props.status];
17-
});
18-
19-
const description = computed(() => {
20-
return {
21-
503: 'Sorry, we are doing some maintenance. Please check back soon.',
22-
500: 'Whoops, something went wrong on our servers.',
23-
404: 'Sorry, the page you are looking for could not be found.',
24-
403: 'Sorry, you are forbidden from accessing this page.',
25-
}[props.status];
26-
});
27-
</script>
28-
29-
<template>
30-
<InertiaHead title="Error" />
31-
<Container fluid>
32-
<main>
33-
<div class="h-screen flex items-center justify-center">
34-
<Card class="p-4 py-6 sm:p-12">
35-
<template #content>
36-
<div class="text-center">
37-
<section>
38-
<h2 class="mb-8 font-extrabold text-5xl md:text-8xl">
39-
{{ title }}
40-
</h2>
41-
<p class="mb-8 text-2xl font-semibold md:text-3xl text-muted-color">
42-
{{ description }}
43-
</p>
44-
<InertiaLink :href="props.homeRoute">
45-
<Button
46-
label="Back to homepage"
47-
raised
48-
>
49-
<template #icon>
50-
<ArrowLeft />
51-
</template>
52-
</Button>
53-
</InertiaLink>
54-
</section>
55-
</div>
56-
</template>
57-
</Card>
58-
</div>
59-
</main>
60-
</Container>
1+
<script setup>
2+
import { computed } from 'vue';
3+
import { ArrowLeft } from 'lucide-vue-next';
4+
5+
const props = defineProps({
6+
homepageRoute: String,
7+
status: Number
8+
});
9+
10+
const title = computed(() => {
11+
return {
12+
503: 'Service Unavailable',
13+
500: 'Server Error',
14+
404: 'Page Not Found',
15+
403: 'Forbidden',
16+
}[props.status];
17+
});
18+
19+
const description = computed(() => {
20+
return {
21+
503: 'Sorry, we are doing some maintenance. Please check back soon.',
22+
500: 'Whoops, something went wrong on our servers.',
23+
404: 'Sorry, the page you are looking for could not be found.',
24+
403: 'Sorry, you are forbidden from accessing this page.',
25+
}[props.status];
26+
});
27+
</script>
28+
29+
<template>
30+
<InertiaHead title="Error" />
31+
<Container fluid>
32+
<main>
33+
<div class="h-screen flex items-center justify-center">
34+
<Card class="p-4 py-6 sm:p-12">
35+
<template #content>
36+
<div class="flex flex-col gap-8 items-center justify-center text-center">
37+
<h1 class="font-extrabold text-5xl md:text-8xl text-primary">
38+
{{ props.status }}
39+
</h1>
40+
<h2 class="font-extrabold text-4xl md:text-6xl">
41+
{{ title }}
42+
</h2>
43+
<p class="text-xl font-semibold md:text-3xl text-muted-color">
44+
{{ description }}
45+
</p>
46+
<InertiaLink :href="props.homepageRoute">
47+
<Button
48+
label="Back to homepage"
49+
raised
50+
>
51+
<template #icon>
52+
<ArrowLeft />
53+
</template>
54+
</Button>
55+
</InertiaLink>
56+
</div>
57+
</template>
58+
</Card>
59+
</div>
60+
</main>
61+
</Container>
6162
</template>

0 commit comments

Comments
 (0)