Skip to content

Commit

Permalink
Merge pull request #926 from ita-social-projects/799-fix-error-pages
Browse files Browse the repository at this point in the history
799 fix error pages
  • Loading branch information
loqimean authored Nov 27, 2024
2 parents 12f3afe + d2b28b4 commit 5325807
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 216 deletions.
3 changes: 2 additions & 1 deletion app/assets/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -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";
17 changes: 17 additions & 0 deletions app/assets/stylesheets/pages/errors.css
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 0 additions & 6 deletions app/controllers/account/users_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
13 changes: 13 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/views/errors/internal_server.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<section class="error-section">
<p class="error-code">500</p>
<p class="error-title"><%= t('500_page.title') %></h1>
<p class="error-description"><%= t('500_page.description') %></p>
</section>
5 changes: 5 additions & 0 deletions app/views/errors/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<section class="error-section">
<p class="error-code">404</p>
<p class="error-title"><%= t('404_page.title') %></h1>
<p class="error-description"><%= t('404_page.description') %></p>
</section>
5 changes: 5 additions & 0 deletions app/views/errors/unprocessable.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<section class="error-section">
<p class="error-code">422</p>
<p class="error-title"><%= t('422_page.title') %></h1>
<p class="error-description"><%= t('422_page.description') %></p>
</section>
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions config/locales/en/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions config/locales/uk/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
67 changes: 0 additions & 67 deletions public/404.html

This file was deleted.

67 changes: 0 additions & 67 deletions public/422.html

This file was deleted.

66 changes: 0 additions & 66 deletions public/500.html

This file was deleted.

9 changes: 0 additions & 9 deletions spec/features/account/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions spec/requests/errors_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5325807

Please sign in to comment.