From fdbc374d7ed8df22d5e49ff2dea801dfad83c4e1 Mon Sep 17 00:00:00 2001 From: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> Date: Wed, 30 Mar 2022 09:06:25 +0200 Subject: [PATCH] #93 - custom error pages (#94) * #93 - wip * #93 - wip * #93 - fix if statement * #93 - wip * #93 - added default error page * #93 - fix to error page * #93 - fix linter * #93 - delete unnecessary file * #93 - added EOL * #93 - fix * #93 - cr fix Co-authored-by: Adrian Hopek --- app/Architecture/ExceptionHandler.php | 18 ++++++ resources/js/Pages/Error.vue | 84 +++++++++++++++++++++++++++ resources/js/Shared/Pagination.vue | 6 +- 3 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 resources/js/Pages/Error.vue diff --git a/app/Architecture/ExceptionHandler.php b/app/Architecture/ExceptionHandler.php index 746f3e1..c63890d 100644 --- a/app/Architecture/ExceptionHandler.php +++ b/app/Architecture/ExceptionHandler.php @@ -5,6 +5,9 @@ declare(strict_types=1); namespace Toby\Architecture; use Illuminate\Foundation\Exceptions\Handler; +use Inertia\Inertia; +use Symfony\Component\HttpFoundation\Response; +use Throwable; class ExceptionHandler extends Handler { @@ -13,4 +16,19 @@ class ExceptionHandler extends Handler "password", "password_confirmation", ]; + + public function render($request, Throwable $e): Response + { + $response = parent::render($request, $e); + + if (app()->environment("production") && in_array($response->status(), [500, 503, 429, 419, 404, 403, 401], true)) { + return Inertia::render("Error", [ + "status" => $response->status(), + ]) + ->toResponse($request) + ->setStatusCode($response->status()); + } + + return $response; + } } diff --git a/resources/js/Pages/Error.vue b/resources/js/Pages/Error.vue new file mode 100644 index 0000000..76bfd45 --- /dev/null +++ b/resources/js/Pages/Error.vue @@ -0,0 +1,84 @@ + + + diff --git a/resources/js/Shared/Pagination.vue b/resources/js/Shared/Pagination.vue index 3cd59e6..4e5975c 100644 --- a/resources/js/Shared/Pagination.vue +++ b/resources/js/Shared/Pagination.vue @@ -21,11 +21,11 @@