diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css index 9a85acf0b..e502a10bf 100644 --- a/app/assets/stylesheets/application.tailwind.css +++ b/app/assets/stylesheets/application.tailwind.css @@ -12,4 +12,5 @@ @import "/components/description_block"; @import "/components/showpage_calculator"; @import "/utilities/custom-utilities"; -@import "/pages/under_construction" +@import "/pages/under_construction"; +@import "/pages/errors"; diff --git a/app/assets/stylesheets/pages/errors.css b/app/assets/stylesheets/pages/errors.css new file mode 100644 index 000000000..bc156a6bd --- /dev/null +++ b/app/assets/stylesheets/pages/errors.css @@ -0,0 +1,17 @@ +@layer components { + .error-section { + @apply mx-auto space-y-4 text-center rounded-lg py-36 bg-white/10 text-success backdrop-blur-md max-w-1230 + } + + .error-section .error-code { + @apply font-bold text-7xl + } + + .error-section .error-title { + @apply text-4xl font-bold + } + + .error-section .error-description { + @apply px-8 text-lg + } +} diff --git a/app/controllers/account/users_controller.rb b/app/controllers/account/users_controller.rb index 4fc589e74..24727b561 100644 --- a/app/controllers/account/users_controller.rb +++ b/app/controllers/account/users_controller.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class Account::UsersController < Account::BaseController - rescue_from ActiveRecord::RecordNotFound, with: :render404 - layout "account" before_action :set_paper_trail_whodunnit @@ -89,8 +87,4 @@ def collection def resource User.find(params[:id]) end - - def render404 - render file: Rails.public_path.join("404.html"), layout: false, status: :not_found - end end diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 000000000..94e43ca8e --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,13 @@ +class ErrorsController < ApplicationController + def not_found + render status: :not_found + end + + def unprocessable + render status: :unprocessable_entity + end + + def internal_server + render status: :internal_server_error + end +end diff --git a/app/views/errors/internal_server.html.erb b/app/views/errors/internal_server.html.erb new file mode 100644 index 000000000..f8844b9c8 --- /dev/null +++ b/app/views/errors/internal_server.html.erb @@ -0,0 +1,5 @@ +
+

500

+

<%= t('500_page.title') %> +

<%= t('500_page.description') %>

+
diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb new file mode 100644 index 000000000..ce949101a --- /dev/null +++ b/app/views/errors/not_found.html.erb @@ -0,0 +1,5 @@ +
+

404

+

<%= t('404_page.title') %> +

<%= t('404_page.description') %>

+
diff --git a/app/views/errors/unprocessable.html.erb b/app/views/errors/unprocessable.html.erb new file mode 100644 index 000000000..a818ccb98 --- /dev/null +++ b/app/views/errors/unprocessable.html.erb @@ -0,0 +1,5 @@ +
+

422

+

<%= t('422_page.title') %> +

<%= t('422_page.description') %>

+
diff --git a/config/application.rb b/config/application.rb index c571dc1bf..820380744 100644 --- a/config/application.rb +++ b/config/application.rb @@ -28,5 +28,7 @@ class Application < Rails::Application config.i18n.load_path += Rails.root.glob("config/locales/**/*.{rb,yml}") config.assets.css_compressor = nil + + config.exceptions_app = routes end end diff --git a/config/locales/en/en.yml b/config/locales/en/en.yml index 3bb164b80..d7f3363da 100644 --- a/config/locales/en/en.yml +++ b/config/locales/en/en.yml @@ -212,6 +212,15 @@ en: calculator-diapers: "Calculator diapers" calculators: "Calculators" message: "Write us a message" + 404_page: + title: "Oops! Page Not Found" + description: "The page you're looking for doesn't exist. It might have been removed, or the link you followed could be broken. Please check the URL or return to the homepage." + 422_page: + title: "Unprocessable Request" + description: "Something went wrong with the data sent. Please review your submission and try again, or return to the previous page." + 500_page: + title: "Internal Server Error" + description: "We encountered an unexpected issue on our end. Please try again later, or contact support if the problem persists." about_us: title: "About Us" description: diff --git a/config/locales/uk/uk.yml b/config/locales/uk/uk.yml index 8ba07e394..a3247fcbc 100644 --- a/config/locales/uk/uk.yml +++ b/config/locales/uk/uk.yml @@ -192,6 +192,15 @@ uk: calculator-diapers: "Калькулятор підгузків" calculators: "Калькулятори" message: "Напишіть нам повідомлення" + 404_page: + title: "Упс! Сторінку не знайдено" + description: "Сторінка, яку ви шукаєте, не існує. Можливо, її було видалено або посилання некоректне. Перевірте URL або поверніться на головну сторінку." + 422_page: + title: "Некоректний запит" + description: "Щось пішло не так з надісланими даними. Перевірте введені дані та спробуйте ще раз або поверніться на попередню сторінку." + 500_page: + title: "Внутрішня помилка сервера" + description: "Ми зіткнулися з неочікуваною проблемою. Будь ласка, спробуйте пізніше або зверніться в службу підтримки, якщо проблема не зникне." about_us: title: "Про нас" description: diff --git a/config/routes.rb b/config/routes.rb index c4ef467b8..7b548e9a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,4 +89,8 @@ end end end + + get "/404", to: "errors#not_found", as: :not_found_error + get "/422", to: "errors#unprocessable", as: :unprocessable_error + get "/500", to: "errors#internal_server", as: :internal_server_error end diff --git a/public/404.html b/public/404.html deleted file mode 100644 index 2be3af26f..000000000 --- a/public/404.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - The page you were looking for doesn't exist (404) - - - - - - -
-
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

-
-

If you are the application owner check the logs for more information.

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

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/public/500.html b/public/500.html deleted file mode 100644 index 78a030af2..000000000 --- a/public/500.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - We're sorry, but something went wrong (500) - - - - - - -
-
-

We're sorry, but something went wrong.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/spec/features/account/users_spec.rb b/spec/features/account/users_spec.rb index d9c51f171..c8652ba17 100644 --- a/spec/features/account/users_spec.rb +++ b/spec/features/account/users_spec.rb @@ -130,13 +130,4 @@ expect(page).to have_content "Re-password doesn't match Password" end end - - describe "user info page" do - context "viewing non-existing user" do - it "renders the 404 page" do - visit account_user_path(id: 1355) - expect(page).to have_content("page you were looking for doesn't exist") - end - end - end end diff --git a/spec/requests/errors_spec.rb b/spec/requests/errors_spec.rb new file mode 100644 index 000000000..fc2b97018 --- /dev/null +++ b/spec/requests/errors_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.describe ErrorsController, type: :request do + describe "GET #not_found" do + it "returns a 404 status" do + get not_found_error_path + + expect(response).to have_http_status(:not_found) + end + end + + describe "GET #unprocessable" do + it "returns a 422 status" do + get unprocessable_error_path + + expect(response).to have_http_status(:unprocessable_entity) + end + end + + describe "GET #internal_server" do + it "returns a 500 status" do + get internal_server_error_path + + expect(response).to have_http_status(:internal_server_error) + end + end +end