From 4513b49423ed31d7a0fa2e4e4cedb31093984f3b Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Thu, 24 Mar 2022 12:25:33 +0100 Subject: [PATCH 01/11] #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 -- 2.52.0 From 0a664cf55d240744b8e98355f18062ffe79092bb Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Fri, 25 Mar 2022 14:12:12 +0100 Subject: [PATCH 02/11] #93 - wip --- resources/js/Pages/Error.vue | 75 +++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/resources/js/Pages/Error.vue b/resources/js/Pages/Error.vue index adfd778..2e5721f 100644 --- a/resources/js/Pages/Error.vue +++ b/resources/js/Pages/Error.vue @@ -1,33 +1,21 @@ @@ -53,11 +41,36 @@ export default { computed: { error() { return { + 401: { + code: '401', + title: 'Nieuprawniony dostęp', + message: 'Aby mieć dostęp do tej strony, musisz się zalogować.', + }, + 403: { + code: '403', + title: 'Zabroniony', + message: 'Dostęp do żądanej strony jest zabroniony.', + }, 404: { code: '404', - title: 'Błąd 404', + title: 'Nie znaleziono strony', message: 'Przykro nam, ale strona, której szukasz, nie istnieje.', }, + 419: { + code: '419', + title: 'Strona wygasła', + message: 'Ta strona wygasła. Zaloguj się ponownie.', + }, + 500: { + code: '500', + title: 'Błąd serwera', + message: 'Wystąpił wewnętrzny błąd serwera.', + }, + 503: { + code: '503', + title: 'Serwis niedostępny', + message: 'Serwer jest tymczasowo niedostępny. Spróbuj ponownie później.', + }, }[this.status] }, -- 2.52.0 From c0d926429608d81de12c4a558c1c27dcc762aaf9 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Mon, 28 Mar 2022 07:46:11 +0200 Subject: [PATCH 03/11] #93 - fix if statement --- app/Architecture/ExceptionHandler.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Architecture/ExceptionHandler.php b/app/Architecture/ExceptionHandler.php index 7a01fd0..5bf05d7 100644 --- a/app/Architecture/ExceptionHandler.php +++ b/app/Architecture/ExceptionHandler.php @@ -6,6 +6,7 @@ namespace Toby\Architecture; use Illuminate\Foundation\Exceptions\Handler; use Inertia\Inertia; +use Symfony\Component\HttpFoundation\Response; use Throwable; class ExceptionHandler extends Handler @@ -16,17 +17,21 @@ class ExceptionHandler extends Handler "password_confirmation", ]; - public function render($request, Throwable $e) + public function render($request, Throwable $e): Response { $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()]) + if (!app()->environment(["local", "testing"]) && in_array($response->status(), [500, 503, 404, 403], true)) { + return Inertia::render("Error", [ + "status" => $response->status(), + ]) ->toResponse($request) ->setStatusCode($response->status()); - } else if ($response->status() === 419) { + } + + if ($response->status() === 419) { return back()->with([ - 'message' => 'The page expired, please try again.', + "message" => "The page expired, please try again.", ]); } -- 2.52.0 From 9dba729b58e7d5bd717df22a4a03be52625c5864 Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 28 Mar 2022 08:53:07 +0200 Subject: [PATCH 04/11] #93 - wip --- app/Architecture/ExceptionHandler.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/Architecture/ExceptionHandler.php b/app/Architecture/ExceptionHandler.php index 5bf05d7..870de22 100644 --- a/app/Architecture/ExceptionHandler.php +++ b/app/Architecture/ExceptionHandler.php @@ -21,7 +21,7 @@ class ExceptionHandler extends Handler { $response = parent::render($request, $e); - if (!app()->environment(["local", "testing"]) && in_array($response->status(), [500, 503, 404, 403], true)) { + if (!app()->environment(["local", "testing"]) && in_array($response->status(), [500, 503, 419, 404, 403], true)) { return Inertia::render("Error", [ "status" => $response->status(), ]) @@ -29,12 +29,6 @@ class ExceptionHandler extends Handler ->setStatusCode($response->status()); } - if ($response->status() === 419) { - return back()->with([ - "message" => "The page expired, please try again.", - ]); - } - return $response; } } -- 2.52.0 From d1ad761ad1ff8d03381306cf5168908d936f301d Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 28 Mar 2022 09:51:45 +0200 Subject: [PATCH 05/11] #93 - added default error page --- app/Architecture/ExceptionHandler.php | 4 +- resources/js/Pages/DefaultError.vue | 76 +++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 resources/js/Pages/DefaultError.vue diff --git a/app/Architecture/ExceptionHandler.php b/app/Architecture/ExceptionHandler.php index 870de22..f05c4d2 100644 --- a/app/Architecture/ExceptionHandler.php +++ b/app/Architecture/ExceptionHandler.php @@ -29,6 +29,8 @@ class ExceptionHandler extends Handler ->setStatusCode($response->status()); } - return $response; + return Inertia::render("DefaultError") + ->toResponse($request) + ->setStatusCode($response->status()); } } diff --git a/resources/js/Pages/DefaultError.vue b/resources/js/Pages/DefaultError.vue new file mode 100644 index 0000000..a9c887f --- /dev/null +++ b/resources/js/Pages/DefaultError.vue @@ -0,0 +1,76 @@ + + + \ No newline at end of file -- 2.52.0 From f33e10d2c0d026ae2c592ee6e0d5a04957bbaa70 Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 28 Mar 2022 10:51:20 +0200 Subject: [PATCH 06/11] #93 - fix to error page --- app/Architecture/ExceptionHandler.php | 6 +-- resources/js/Pages/DefaultError.vue | 76 --------------------------- resources/js/Pages/Error.vue | 5 ++ 3 files changed, 7 insertions(+), 80 deletions(-) delete mode 100644 resources/js/Pages/DefaultError.vue diff --git a/app/Architecture/ExceptionHandler.php b/app/Architecture/ExceptionHandler.php index f05c4d2..6c17323 100644 --- a/app/Architecture/ExceptionHandler.php +++ b/app/Architecture/ExceptionHandler.php @@ -21,7 +21,7 @@ class ExceptionHandler extends Handler { $response = parent::render($request, $e); - if (!app()->environment(["local", "testing"]) && in_array($response->status(), [500, 503, 419, 404, 403], true)) { + if (!app()->environment(["local", "testing"]) && in_array($response->status(), [500, 503, 429, 419, 404, 403, 401], true)) { return Inertia::render("Error", [ "status" => $response->status(), ]) @@ -29,8 +29,6 @@ class ExceptionHandler extends Handler ->setStatusCode($response->status()); } - return Inertia::render("DefaultError") - ->toResponse($request) - ->setStatusCode($response->status()); + return $response; } } diff --git a/resources/js/Pages/DefaultError.vue b/resources/js/Pages/DefaultError.vue deleted file mode 100644 index a9c887f..0000000 --- a/resources/js/Pages/DefaultError.vue +++ /dev/null @@ -1,76 +0,0 @@ - - - \ No newline at end of file diff --git a/resources/js/Pages/Error.vue b/resources/js/Pages/Error.vue index 2e5721f..f01e30e 100644 --- a/resources/js/Pages/Error.vue +++ b/resources/js/Pages/Error.vue @@ -61,6 +61,11 @@ export default { title: 'Strona wygasła', message: 'Ta strona wygasła. Zaloguj się ponownie.', }, + 429: { + code: '429', + title: 'Przekroczono limit zapytań', + message: 'Wysłano ostatnio zbyt wiele zapytań. Poczekaj i spróbuj ponownie później.' + }, 500: { code: '500', title: 'Błąd serwera', -- 2.52.0 From 168872183d246370e090e0a5c3b53a2380cd8512 Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 28 Mar 2022 11:00:30 +0200 Subject: [PATCH 07/11] #93 - fix linter --- resources/js/Pages/Error.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/Pages/Error.vue b/resources/js/Pages/Error.vue index f01e30e..71e54ce 100644 --- a/resources/js/Pages/Error.vue +++ b/resources/js/Pages/Error.vue @@ -64,7 +64,7 @@ export default { 429: { code: '429', title: 'Przekroczono limit zapytań', - message: 'Wysłano ostatnio zbyt wiele zapytań. Poczekaj i spróbuj ponownie później.' + message: 'Wysłano ostatnio zbyt wiele zapytań. Poczekaj i spróbuj ponownie później.', }, 500: { code: '500', -- 2.52.0 From 6129a384a63281aa47a11419c0ce6c2bd1a1c02d Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 28 Mar 2022 11:09:58 +0200 Subject: [PATCH 08/11] #93 - delete unnecessary file --- resources/js/Composables/errorInfo.js | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 resources/js/Composables/errorInfo.js diff --git a/resources/js/Composables/errorInfo.js b/resources/js/Composables/errorInfo.js deleted file mode 100644 index 45b9eb2..0000000 --- a/resources/js/Composables/errorInfo.js +++ /dev/null @@ -1,16 +0,0 @@ -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, - } -} -- 2.52.0 From 79fc6883a669e55925ab680e1d43c3cd3818fcfc Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 28 Mar 2022 11:12:48 +0200 Subject: [PATCH 09/11] #93 - added EOL --- resources/js/Pages/Error.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/Pages/Error.vue b/resources/js/Pages/Error.vue index 71e54ce..76bfd45 100644 --- a/resources/js/Pages/Error.vue +++ b/resources/js/Pages/Error.vue @@ -81,4 +81,4 @@ export default { }, } - \ No newline at end of file + -- 2.52.0 From cfa7be65b5b6dbb2ba4641df982d459d4fc3f61a Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 28 Mar 2022 11:21:21 +0200 Subject: [PATCH 10/11] #93 - fix --- resources/js/Shared/Pagination.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 @@