From 84b8bb0a43b739a81c63712f4da0873a0f9a06aa Mon Sep 17 00:00:00 2001 From: Andy Smith Date: Tue, 29 Jul 2025 13:32:00 -0500 Subject: [PATCH] Add controller, routes, and templates for other error pages --- app/controllers/errors_controller.rb | 25 +++ app/views/errors/bad_request.html.erb | 7 + .../errors/internal_server_error.html.erb | 7 + app/views/errors/not_acceptable.html.erb | 7 + app/views/errors/not_found.html.erb | 7 + .../errors/unprocessable_entity.html.erb | 7 + app/views/layouts/error.html.erb | 164 ++++++++++++++++++ config/application.rb | 3 + config/routes.rb | 6 + public/400.html | 114 ------------ public/404.html | 148 ---------------- public/406-unsupported-browser.html | 156 ----------------- public/422.html | 114 ------------ public/500.html | 114 ------------ 14 files changed, 233 insertions(+), 646 deletions(-) create mode 100644 app/controllers/errors_controller.rb create mode 100644 app/views/errors/bad_request.html.erb create mode 100644 app/views/errors/internal_server_error.html.erb create mode 100644 app/views/errors/not_acceptable.html.erb create mode 100644 app/views/errors/not_found.html.erb create mode 100644 app/views/errors/unprocessable_entity.html.erb create mode 100644 app/views/layouts/error.html.erb delete mode 100644 public/400.html delete mode 100644 public/404.html delete mode 100644 public/406-unsupported-browser.html delete mode 100644 public/422.html delete mode 100644 public/500.html diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 000000000..168dc12e3 --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,25 @@ +class ErrorsController < ApplicationController + require_untenanted_access + + layout "error" + + def bad_request + render status: :bad_request + end + + def not_found + render status: :not_found + end + + def not_acceptable + render status: :not_acceptable + end + + def unprocessable_entity + render status: :unprocessable_entity + end + + def internal_server_error + render status: :internal_server_error + end +end diff --git a/app/views/errors/bad_request.html.erb b/app/views/errors/bad_request.html.erb new file mode 100644 index 000000000..19e31fe91 --- /dev/null +++ b/app/views/errors/bad_request.html.erb @@ -0,0 +1,7 @@ +
+

400

+

Bad request

+
+
Your request could not be understood by the server.
+
+ diff --git a/app/views/errors/internal_server_error.html.erb b/app/views/errors/internal_server_error.html.erb new file mode 100644 index 000000000..1f7802f17 --- /dev/null +++ b/app/views/errors/internal_server_error.html.erb @@ -0,0 +1,7 @@ +
+

500

+

Internal server error

+
+
Something went wrong on our end; please try again later.
+
+ diff --git a/app/views/errors/not_acceptable.html.erb b/app/views/errors/not_acceptable.html.erb new file mode 100644 index 000000000..976cc0d89 --- /dev/null +++ b/app/views/errors/not_acceptable.html.erb @@ -0,0 +1,7 @@ +
+

406

+

Not acceptable

+
+
The requested resource is not available in a format acceptable to your browser.
+
+ diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb new file mode 100644 index 000000000..f3e9f5e23 --- /dev/null +++ b/app/views/errors/not_found.html.erb @@ -0,0 +1,7 @@ +
+

404

+

Sorry, that page doesn’t exist!

+
+
You may have mistyped the address or the page may have moved.
+
+ diff --git a/app/views/errors/unprocessable_entity.html.erb b/app/views/errors/unprocessable_entity.html.erb new file mode 100644 index 000000000..2e6d18d0d --- /dev/null +++ b/app/views/errors/unprocessable_entity.html.erb @@ -0,0 +1,7 @@ +
+

422

+

Unprocessable entity

+
+
The server understands the request but was unable to process it.
+
+ diff --git a/app/views/layouts/error.html.erb b/app/views/layouts/error.html.erb new file mode 100644 index 000000000..869707883 --- /dev/null +++ b/app/views/layouts/error.html.erb @@ -0,0 +1,164 @@ + + + + The page you were looking for doesn’t exist (404 Not found) + + + + + + + + <%= yield %> + Go back + + diff --git a/config/application.rb b/config/application.rb index 3fc46a769..c39007fb2 100644 --- a/config/application.rb +++ b/config/application.rb @@ -28,5 +28,8 @@ module Fizzy # enable load_async config.active_record.async_query_executor = :global_thread_pool + + # use routes for error pages instead of static files + config.exceptions_app = self.routes end end diff --git a/config/routes.rb b/config/routes.rb index 2a1554e84..15921bb86 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -179,6 +179,12 @@ Rails.application.routes.draw do get "manifest" => "rails/pwa#manifest", as: :pwa_manifest get "service-worker" => "pwa#service_worker" + match "/400", to: "errors#bad_request", via: :all + match "/404", to: "errors#not_found", via: :all + match "/406", to: "errors#not_acceptable", via: :all + match "/422", to: "errors#unprocessable_entity", via: :all + match "/500", to: "errors#internal_server_error", via: :all + root "events#index" Queenbee.routes(self) diff --git a/public/400.html b/public/400.html deleted file mode 100644 index 282dbc8cc..000000000 --- a/public/400.html +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - The server cannot process the request due to a client error (400 Bad Request) - - - - - - - - - - - - - -
-
- -
-
-

The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.

-
-
- - - - diff --git a/public/404.html b/public/404.html deleted file mode 100644 index 6829f81bf..000000000 --- a/public/404.html +++ /dev/null @@ -1,148 +0,0 @@ - - - - The page you were looking for doesn’t exist (404 Not found) - - - - - - - -
- -
-
404
-
Sorry, that page does‘t exist!
-
You may have mistyped the address or the page may have moved
-
-
- - - diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html deleted file mode 100644 index f78ac9454..000000000 --- a/public/406-unsupported-browser.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - Your browser is not supported (406) - - - - - - -
-
- - - -
- - - - - Go back - -
-

🇺🇸 Upgrade to a supported web browser. Fizzy requires a modern web browser. Please use one of the browsers listed below and make sure auto-updates are enabled.

-

🇪🇸 Actualiza a un navegador web compatible. Fizzy requiere un navegador web moderno. Utiliza uno de los navegadores listados a continuación y asegúrate de que las actualizaciones automáticas estén habilitadas.

-

🇫🇷 Mettez à jour vers un navigateur web pris en charge. Fizzy nécessite un navigateur web moderne. Veuillez utiliser l'un des navigateurs répertoriés ci-dessous et assurez-vous que les mises à jour automatiques sont activées.

-

🇮🇳 समर्थित वेब ब्राउज़र में अपग्रेड करें। Fizzy को एक आधुनिक वेब ब्राउज़र की आवश्यकता है। कृपया नीचे सूचीबद्ध ब्राउज़रों में से कोई एक का उपयोग करें और सुनिश्चित करें कि स्वचालित अपडेट्स सक्षम हैं।

-

🇩🇪 Aktualisieren Sie auf einen unterstützten Webbrowser. Fizzy erfordert einen modernen Webbrowser. Verwenden Sie bitte einen der unten aufgeführten Browser und stellen Sie sicher, dass automatische Updates aktiviert sind.

-

🇧🇷 Atualize para um navegador compatível. O Fizzy requer um navegador moderno. Por favor, use um dos navegadores listados abaixo e certifique-se de que as atualizações automáticas estão ativadas.

-

Safari 17.2+, Chrome 119+, Firefox 121+, Opera 104+

-
-
- - diff --git a/public/422.html b/public/422.html deleted file mode 100644 index 8bcf06014..000000000 --- a/public/422.html +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - The change you wanted was rejected (422 Unprocessable Entity) - - - - - - - - - - - - - -
-
- -
-
-

The change you wanted was rejected. Maybe you tried to change something you didn’t have access to. If you’re the application owner check the logs for more information.

-
-
- - - - diff --git a/public/500.html b/public/500.html deleted file mode 100644 index d77718c3a..000000000 --- a/public/500.html +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - We’re sorry, but something went wrong (500 Internal Server Error) - - - - - - - - - - - - - -
-
- -
-
-

We’re sorry, but something went wrong.
If you’re the application owner check the logs for more information.

-
-
- - - -