From 89e9154499f67fd8c63e1098b3e50b317c690dd0 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 5 May 2014 12:22:52 +0200 Subject: custom error pages for 404 and 500 errors --- app/controllers/errors_controller.rb | 9 +++++++++ app/views/errors/not_found.html.haml | 7 +++++++ app/views/errors/server_error.html.haml | 7 +++++++ config/application.rb | 2 ++ config/routes.rb | 3 +++ 5 files changed, 28 insertions(+) create mode 100644 app/controllers/errors_controller.rb create mode 100644 app/views/errors/not_found.html.haml create mode 100644 app/views/errors/server_error.html.haml diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 0000000..bf9329c --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,9 @@ +class ErrorsController < ApplicationController + + def not_found + end + + def server_error + end + +end diff --git a/app/views/errors/not_found.html.haml b/app/views/errors/not_found.html.haml new file mode 100644 index 0000000..22b6a55 --- /dev/null +++ b/app/views/errors/not_found.html.haml @@ -0,0 +1,7 @@ +.hero-unit + %h1 Page not found. + %h2 The page you were looking for doesn't exist. + %p.lead You may have mistyped the address or the page may have moved. + %a.btn.btn-primary.btn-large{href:'/'} + %i.icon-home.icon-white + Home diff --git a/app/views/errors/server_error.html.haml b/app/views/errors/server_error.html.haml new file mode 100644 index 0000000..173cdad --- /dev/null +++ b/app/views/errors/server_error.html.haml @@ -0,0 +1,7 @@ +.hero-unit + %h1 Ouch! + %h2 We ran into a server error. + %p.lead The problem has been logged and we will look into it. + %a.btn.btn-primary.btn-large{href:'/'} + %i.icon-home.icon-white + Home diff --git a/config/application.rb b/config/application.rb index 2c9c55a..1077198 100644 --- a/config/application.rb +++ b/config/application.rb @@ -91,5 +91,7 @@ module LeapWeb ## see initializers/customization.rb ## config.paths['app/views'].unshift "config/customization/views" + + config.exceptions_app = self.routes end end diff --git a/config/routes.rb b/config/routes.rb index 745b97d..f92c704 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,9 @@ LeapWeb::Application.routes.draw do root :to => "home#index" get '(:locale)' => 'home#index', :locale => MATCH_LOCALE, :as => 'home' + match '/404' => 'errors#not_found' + match '/500' => 'errors#server_error' + scope "(:locale)", :locale => MATCH_LOCALE, :controller => 'pages', :action => 'show' do get 'privacy-policy', :as => 'privacy_policy' get 'terms-of-service', :as => 'terms_of_service' -- cgit v1.2.3 From 97e30cc136a72092abba19f1b601ad9d5ebd5257 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 5 May 2014 12:29:21 +0200 Subject: i18n for error pages --- app/views/errors/not_found.html.haml | 8 ++++---- app/views/errors/server_error.html.haml | 8 ++++---- config/locales/en.yml | 9 +++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/views/errors/not_found.html.haml b/app/views/errors/not_found.html.haml index 22b6a55..75cb889 100644 --- a/app/views/errors/not_found.html.haml +++ b/app/views/errors/not_found.html.haml @@ -1,7 +1,7 @@ .hero-unit - %h1 Page not found. - %h2 The page you were looking for doesn't exist. - %p.lead You may have mistyped the address or the page may have moved. + %h1=t :not_found_title + %h2=t :not_found_subtitle + %p.lead=t :not_found_lead %a.btn.btn-primary.btn-large{href:'/'} %i.icon-home.icon-white - Home + =t :home diff --git a/app/views/errors/server_error.html.haml b/app/views/errors/server_error.html.haml index 173cdad..68baf20 100644 --- a/app/views/errors/server_error.html.haml +++ b/app/views/errors/server_error.html.haml @@ -1,7 +1,7 @@ .hero-unit - %h1 Ouch! - %h2 We ran into a server error. - %p.lead The problem has been logged and we will look into it. + %h1=t :server_error_title + %h2=t :server_error_subtitle + %p.lead=t :server_error_lead %a.btn.btn-primary.btn-large{href:'/'} %i.icon-home.icon-white - Home + =t :home diff --git a/config/locales/en.yml b/config/locales/en.yml index cebf075..899d659 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,10 +1,19 @@ en: + home: Home privacy_policy: Privacy Policy terms_of_service: Terms of Service pricing: Pricing about: About Us contact: Contact + + not_found_title: Page not found. + not_found_subtitle: "The page you were looking for doesn't exist." + not_found_lead: "You may have mistyped the address or the page may have moved." + server_error_title: Ouch! + server_error_subtitle: We ran into a server error. + server_error_lead: The problem has been logged and we will look into it. no_such_thing: "No such %{thing}." + thing_was_successfully_created: "%{thing} was successfully created." create_thing: "Create %{thing}" -- cgit v1.2.3 From 8f9e6d294c78a4c3c2336ca4386fda3e20b2d365 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 6 May 2014 09:50:35 +0200 Subject: minor: remove unused error pages --- public/404.html | 26 -------------------------- public/500.html | 25 ------------------------- 2 files changed, 51 deletions(-) delete mode 100644 public/404.html delete mode 100644 public/500.html diff --git a/public/404.html b/public/404.html deleted file mode 100644 index 9a48320..0000000 --- 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/500.html b/public/500.html deleted file mode 100644 index f3648a0..0000000 --- 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.

-
- - -- cgit v1.2.3 From b298cea527f74f682d24defee360e0f45f47d125 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 6 May 2014 09:50:46 +0200 Subject: little bit of documentation --- app/controllers/errors_controller.rb | 5 +++-- config/application.rb | 1 + config/routes.rb | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index bf9329c..6c659e6 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -1,9 +1,10 @@ +# We render http errors ourselves so we can customize them class ErrorsController < ApplicationController - + # 404 def not_found end + # 500 def server_error end - end diff --git a/config/application.rb b/config/application.rb index 1077198..8555f48 100644 --- a/config/application.rb +++ b/config/application.rb @@ -92,6 +92,7 @@ module LeapWeb ## config.paths['app/views'].unshift "config/customization/views" + # handle http errors ourselves config.exceptions_app = self.routes end end diff --git a/config/routes.rb b/config/routes.rb index f92c704..9e0b72d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,10 @@ LeapWeb::Application.routes.draw do root :to => "home#index" get '(:locale)' => 'home#index', :locale => MATCH_LOCALE, :as => 'home' + # + # HTTP Error Handling + # instead of the default error pages use the errors controller and views + # match '/404' => 'errors#not_found' match '/500' => 'errors#server_error' -- cgit v1.2.3