From f2d37796c6bce5ebfca7992af8214d8af00a170d Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Sun, 28 Jan 2018 22:10:03 +0100 Subject: [PATCH 1/2] custom error pages --- app/assets/stylesheets/application.css.scss | 12 +++++++++ app/controllers/errors_controller.rb | 9 +++++++ .../errors/internal_server_error.html.erb | 8 ++++++ app/views/errors/not_found.html.erb | 8 ++++++ config/application.rb | 3 +++ config/routes.rb | 2 ++ public/404.html | 26 ------------------- public/422.html | 26 ------------------- public/500.html | 25 ------------------ 9 files changed, 42 insertions(+), 77 deletions(-) create mode 100644 app/controllers/errors_controller.rb create mode 100644 app/views/errors/internal_server_error.html.erb create mode 100644 app/views/errors/not_found.html.erb delete mode 100644 public/404.html delete mode 100644 public/422.html delete mode 100644 public/500.html diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 364c77d35..b24eb34d2 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -895,3 +895,15 @@ form .checkbox input[type="checkbox"] { } } } + +.errors { + padding: 3em; + + h3 { + margin-left: auto; + margin-right: auto; + max-width: 75%; + padding: 1em; + line-height: 1.6em; + } +} \ No newline at end of file diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 000000000..479fe79df --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,9 @@ +class ErrorsController < ApplicationController + def not_found + render status: 404 + end + + def internal_server_error + render status: 500 + end +end 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..80e296e44 --- /dev/null +++ b/app/views/errors/internal_server_error.html.erb @@ -0,0 +1,8 @@ +
+

Internal server error

+

+ We're sorry, there seems to be an error with this request. + A notification has automatically been sent to us, and we will resolve this as soon as possible. +

+

<%= link_to 'Home', root_path, class: 'btn btn-default' %>

+
\ No newline at end of file diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb new file mode 100644 index 000000000..1c75680d6 --- /dev/null +++ b/app/views/errors/not_found.html.erb @@ -0,0 +1,8 @@ +
+

Not found

+

+ The page you were looking for doesn't exist. + You may have mistyped the address or the page may have moved. +

+

<%= link_to 'Home', root_path, class: 'btn btn-default' %>

+
\ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 0617d3e5e..97613f125 100644 --- a/config/application.rb +++ b/config/application.rb @@ -25,5 +25,8 @@ class Application < Rails::Application # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true + + # This tells Rails to serve error pages from the app itself, rather than using static error pages in public/ + config.exceptions_app = self.routes end end diff --git a/config/routes.rb b/config/routes.rb index 409c52190..480f87f54 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,4 +78,6 @@ end end + match '/404', to: 'errors#not_found', via: :all + match '/500', to: 'errors#internal_server_error', via: :all end diff --git a/public/404.html b/public/404.html deleted file mode 100644 index 9a48320a5..000000000 --- a/public/404.html +++ /dev/null @@ -1,26 +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.

-
- - diff --git a/public/422.html b/public/422.html deleted file mode 100644 index 83660ab18..000000000 --- a/public/422.html +++ /dev/null @@ -1,26 +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.

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

We're sorry, but something went wrong.

-
- - From 00b0e3c862e95627bc2180be84e7814fb2aab9ed Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Mon, 29 Jan 2018 11:51:41 +0100 Subject: [PATCH 2/2] error pages: integrate i18n --- app/views/errors/internal_server_error.html.erb | 9 +++------ app/views/errors/not_found.html.erb | 9 +++------ config/locales/en.yml | 7 +++++++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/views/errors/internal_server_error.html.erb b/app/views/errors/internal_server_error.html.erb index 80e296e44..24030fbba 100644 --- a/app/views/errors/internal_server_error.html.erb +++ b/app/views/errors/internal_server_error.html.erb @@ -1,8 +1,5 @@
-

Internal server error

-

- We're sorry, there seems to be an error with this request. - A notification has automatically been sent to us, and we will resolve this as soon as possible. -

-

<%= link_to 'Home', root_path, class: 'btn btn-default' %>

+

<%= t('.title') %>

+

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

+

<%= link_to t('global.home'), root_path, class: 'btn btn-default' %>

\ No newline at end of file diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb index 1c75680d6..24030fbba 100644 --- a/app/views/errors/not_found.html.erb +++ b/app/views/errors/not_found.html.erb @@ -1,8 +1,5 @@
-

Not found

-

- The page you were looking for doesn't exist. - You may have mistyped the address or the page may have moved. -

-

<%= link_to 'Home', root_path, class: 'btn btn-default' %>

+

<%= t('.title') %>

+

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

+

<%= link_to t('global.home'), root_path, class: 'btn btn-default' %>

\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 2e26b68a1..af07cb283 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -265,6 +265,12 @@ en: send_paranoid_instructions: If your account exists, you will receive an email with instructions about how to unlock it in a few minutes. unlocked: Your account has been unlocked successfully. Please sign in to continue. errors: + internal_server_error: + title: Internal server error + description: We're sorry, there seems to be an error with this request. A notification has automatically been sent to us, and we will resolve this as soon as possible. + not_found: + title: Not found + description: The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved. messages: already_confirmed: was already confirmed, please try signing in confirmation_period_expired: needs to be confirmed within %{period}, please request a new one @@ -289,6 +295,7 @@ en: edit: Update filter: Filter give_time: Time transfer + home: Home information: Information locales_header: change language member_count: 'Number of users:'