#93 - custom error pages #94

Merged
EwelinaLasowy merged 11 commits from #93-custom-error-pages into main 2022-03-30 09:06:25 +02:00
3 changed files with 101 additions and 0 deletions
Showing only changes of commit 4513b49423 - Show all commits

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace Toby\Architecture; namespace Toby\Architecture;
use Illuminate\Foundation\Exceptions\Handler; use Illuminate\Foundation\Exceptions\Handler;
use Inertia\Inertia;
use Throwable;
class ExceptionHandler extends Handler class ExceptionHandler extends Handler
{ {
@@ -13,4 +15,21 @@ class ExceptionHandler extends Handler
"password", "password",
krzysztofrewak commented 2022-03-28 11:25:57 +02:00 (Migrated from github.com)
Review

Why only these statuses? Plus it would be nice to move this array to some const maybe?

Why only these statuses? Plus it would be nice to move this array to some const maybe?
krzysztofrewak commented 2022-03-28 11:26:27 +02:00 (Migrated from github.com)
Review

And why not testing? It would be nice to have a way to test failed operations.

And why not testing? It would be nice to have a way to test failed operations.
EwelinaLasowy commented 2022-03-29 10:52:46 +02:00 (Migrated from github.com)
Review

These statuses are rendered by default by Laravel. The solution itself is proposed by the creator of Inertia link, so I think that will be waste of time to make something more complicated. I've changed environment to production only. Maybe we can think about the application sidebar when the user is signed in, but it will be here some technical complications and it could be confusing to users.

These statuses are rendered by default by Laravel. The solution itself is proposed by the creator of Inertia [link](https://inertiajs.com/error-handling), so I think that will be waste of time to make something more complicated. I've changed `environment` to production only. Maybe we can think about the application sidebar when the user is signed in, but it will be here some technical complications and it could be confusing to users.
"password_confirmation", "password_confirmation",
]; ];
public function render($request, Throwable $e)
{
$response = parent::render($request, $e);
if (!app()->environment(['local', 'testing']) && in_array($response->status(), [500, 503, 404, 403])) {
return Inertia::render('Error', ['status' => $response->status()])
->toResponse($request)
->setStatusCode($response->status());
} else if ($response->status() === 419) {
return back()->with([
'message' => 'The page expired, please try again.',
]);
}
return $response;
}
} }

View File

@@ -0,0 +1,16 @@
const errors = [
{
'title': '404',
'description': 'Nie znaleziono strony',
},
]
export function useErrorInfo() {
const getErrors = () => errors
const findErrors = value => errors.find(error => error.value === value)
return {
getErrors,
findErrors,
}
}

View File

@@ -0,0 +1,66 @@
<template>
<InertiaHead :title="error.title" />
<div class="min-h-screen pt-16 pb-12 flex flex-col">
<main class="flex-grow flex flex-col justify-center max-w-7xl w-full mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex-shrink-0 flex justify-center">
<div>
<InertiaLink
href="/"
class="inline-flex items-center"
>
<img
class="block h-16 w-auto"
src="/img/logo.png"
alt="Logo"
>
</InertiaLink>
</div>
</div>
<div class="py-8">
<div class="text-center">
<p class="text-7xl font-semibold text-blumilk-500 uppercase tracking-wide">
{{ error.code }}
</p>
<h1 class="mt-2 text-2xl font-extrabold text-gray-900 tracking-tight">
{{ error.title }}
</h1>
<p class="mt-2 text-base text-gray-500">
{{ error.message }}
</p>
<div class="mt-6">
<InertiaLink
href="/"
class="inline-flex items-center px-4 py-3 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-blumilk-600 hover:bg-blumilk-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
>
Wróć do strony głównej
</InertiaLink>
</div>
</div>
</div>
</main>
</div>
</template>
<script>
import GuestLayout from '@/Shared/Layout/GuestLayout'
export default {
name: 'ErrorPage',
layout: GuestLayout,
props: {
status: Number,
},
computed: {
error() {
return {
404: {
code: '404',
title: 'Błąd 404',
message: 'Przykro nam, ale strona, której szukasz, nie istnieje.',
},
}[this.status]
},
},
}
</script>