From 4513b49423ed31d7a0fa2e4e4cedb31093984f3b Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Thu, 24 Mar 2022 12:25:33 +0100 Subject: [PATCH] #93 - wip --- app/Architecture/ExceptionHandler.php | 19 ++++++++ resources/js/Composables/errorInfo.js | 16 +++++++ resources/js/Pages/Error.vue | 66 +++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 resources/js/Composables/errorInfo.js create mode 100644 resources/js/Pages/Error.vue diff --git a/app/Architecture/ExceptionHandler.php b/app/Architecture/ExceptionHandler.php index 746f3e1..7a01fd0 100644 --- a/app/Architecture/ExceptionHandler.php +++ b/app/Architecture/ExceptionHandler.php @@ -5,6 +5,8 @@ declare(strict_types=1); namespace Toby\Architecture; use Illuminate\Foundation\Exceptions\Handler; +use Inertia\Inertia; +use Throwable; class ExceptionHandler extends Handler { @@ -13,4 +15,21 @@ class ExceptionHandler extends Handler "password", "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; + } } diff --git a/resources/js/Composables/errorInfo.js b/resources/js/Composables/errorInfo.js new file mode 100644 index 0000000..45b9eb2 --- /dev/null +++ b/resources/js/Composables/errorInfo.js @@ -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, + } +} diff --git a/resources/js/Pages/Error.vue b/resources/js/Pages/Error.vue new file mode 100644 index 0000000..adfd778 --- /dev/null +++ b/resources/js/Pages/Error.vue @@ -0,0 +1,66 @@ + + + \ No newline at end of file