From a753792d325c41190c1d98f3973fbf57bb71114f Mon Sep 17 00:00:00 2001 From: Alberto Renteria Correa Date: Thu, 15 Dec 2016 16:27:08 +1100 Subject: [PATCH 01/17] 404 page redesign --- public/404.html | 68 ++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/public/404.html b/public/404.html index aa201306d2..5279c2d164 100644 --- a/public/404.html +++ b/public/404.html @@ -5,53 +5,39 @@ + + - -
- -

So sorry we can't find that page.

-

In the meantime, here is a $20 voucher to make up for your time - just use this code @checkout: OOPS20

-

- Go to the homepage -

-

- If you would like some further assistance, feel free to email: -

-

- team@fameandpartners.com -

-
- + ga('create', 'UA-41247818-1', 'auto'); + ga('send', 'pageview'); + ga('send', 'event', '404', 'not found'); + From c3022151997322d1c0bac2fa5fa75bc4b7754e42 Mon Sep 17 00:00:00 2001 From: Alberto Renteria Correa Date: Fri, 16 Dec 2016 15:57:36 +1100 Subject: [PATCH 02/17] Fix css format --- public/404.html | 68 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/public/404.html b/public/404.html index 5279c2d164..311dfd6768 100644 --- a/public/404.html +++ b/public/404.html @@ -3,19 +3,63 @@ The page you were looking for doesn't exist (404) @@ -23,11 +67,13 @@ -
-

Looking for something?

-

Sorry, this page doesn't exist.

-

Try our homepage to see what's new and start customizing.

-

Still can't find what you're looking for? E-mail us at team@fameandpartners.com

+
+
+

Looking for something?

+

Sorry, this page doesn't exist.

+

Try our homepage to see what's new and start customizing.

+

Still can't find what you're looking for? E-mail us at team@fameandpartners.com

+
- - - - - -
-
-

Looking for something?

-

Sorry, this page doesn't exist.

-

Try our homepage to see what's new and start customizing.

-

Still can't find what you're looking for? E-mail us at team@fameandpartners.com

-
-
- - - From c6e458758c90ff2d3be75fa77ee65096f0a9feee Mon Sep 17 00:00:00 2001 From: Alberto Renteria Correa Date: Thu, 22 Dec 2016 12:52:40 +1100 Subject: [PATCH 05/17] Add new controller and helper --- app/controllers/errors_controller.rb | 8 ++++++++ app/helpers/errors_helper.rb | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 app/controllers/errors_controller.rb create mode 100644 app/helpers/errors_helper.rb diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 0000000000..16dba8f831 --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,8 @@ +class ErrorsController < ApplicationController + def not_found + render(:status => 404) + end + + def internal_server_error + end +end diff --git a/app/helpers/errors_helper.rb b/app/helpers/errors_helper.rb new file mode 100644 index 0000000000..8e3b415c57 --- /dev/null +++ b/app/helpers/errors_helper.rb @@ -0,0 +1,2 @@ +module ErrorsHelper +end From 6488abfc0dee37014aa7dba6cca995e94745b78c Mon Sep 17 00:00:00 2001 From: Alberto Renteria Correa Date: Thu, 22 Dec 2016 12:54:40 +1100 Subject: [PATCH 06/17] Add new 404 template --- app/views/errors/not_found.html.slim | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/views/errors/not_found.html.slim diff --git a/app/views/errors/not_found.html.slim b/app/views/errors/not_found.html.slim new file mode 100644 index 0000000000..4365afe0cc --- /dev/null +++ b/app/views/errors/not_found.html.slim @@ -0,0 +1,25 @@ +.error-page.text-center + h1 + | Looking for something? + h2 + | Sorry, this page doesn't exist. + p + | Try our #{link_to "homepage", '/'} to see what's new and start customizing. + p.thin-bottom + | Still can't find what you're looking for? #{link_to "E-mail us", 'mailto:team@fameandpartners.com'} at team@fameandpartners.com. + +javascript: + (function (i, s, o, g, r, a, m) { + i['GoogleAnalyticsObject'] = r; + i[r] = i[r] || function () { + (i[r].q = i[r].q || []).push(arguments) + }, i[r].l = 1 * new Date(); + a = s.createElement(o), + m = s.getElementsByTagName(o)[0]; + a.async = 1; + a.src = g; + m.parentNode.insertBefore(a, m) + })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); + ga('create', 'UA-41247818-1', 'auto'); + ga('send', 'pageview'); + ga('send', 'event', '404', 'not found'); From 47fc5cf2ab8cf0626e9e20cfc2c9f6d82c7187db Mon Sep 17 00:00:00 2001 From: Alberto Renteria Correa Date: Thu, 22 Dec 2016 12:55:50 +1100 Subject: [PATCH 07/17] Add new route to the 404 page --- config/routes.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 381c177e97..2c47655bcd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -424,6 +424,12 @@ mount Spree::Core::Engine, at: '/' + ######## + # 404 Error Pages + ######## + + get "/404", :to => "errors#not_found", :via => :all + ############################################ # Storefront (Search, Checkout and Payments) ############################################ From e1bcb6860049dfdb2e4c556cee4720e5b72974b6 Mon Sep 17 00:00:00 2001 From: Alberto Renteria Correa Date: Thu, 22 Dec 2016 12:56:40 +1100 Subject: [PATCH 08/17] Tell rails to use tempaltes --- config/application.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/application.rb b/config/application.rb index f4be33c31b..4e68cf7a32 100644 --- a/config/application.rb +++ b/config/application.rb @@ -119,6 +119,9 @@ class Application < Rails::Application config.skip_mail_delivery = false + #Use route for error handling + config.exceptions_app = self.routes + config.generators do |generator| generator.test_framework :rspec end From 6090944f070f77742fa90cedd1133408bf621f3f Mon Sep 17 00:00:00 2001 From: Alberto Renteria Correa Date: Thu, 22 Dec 2016 12:57:44 +1100 Subject: [PATCH 09/17] Error pages sass --- .../stylesheets/application_redesign.css.scss | 1 + app/assets/stylesheets/redesign/_error.scss | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 app/assets/stylesheets/redesign/_error.scss diff --git a/app/assets/stylesheets/application_redesign.css.scss b/app/assets/stylesheets/application_redesign.css.scss index 13c6d4966a..8d39de1629 100644 --- a/app/assets/stylesheets/application_redesign.css.scss +++ b/app/assets/stylesheets/application_redesign.css.scss @@ -168,6 +168,7 @@ z-index levels @import 'redesign/style_session'; @import 'redesign/tables'; @import 'redesign/pages'; +@import 'redesign/error'; // Checkout @import 'redesign/pages/page-checkout'; diff --git a/app/assets/stylesheets/redesign/_error.scss b/app/assets/stylesheets/redesign/_error.scss new file mode 100644 index 0000000000..8335fad7e2 --- /dev/null +++ b/app/assets/stylesheets/redesign/_error.scss @@ -0,0 +1,35 @@ +// 404 - 500 Pages +.error-page { + margin: 100px auto; + + h1 { + font-size: 3.8em; + margin-top: 0; + } + + h2 { + font-size: 3.2rem; + margin: 50px 0; + } + + p { + font-size: 2rem; + font-weight: 300; + line-height: 150%; + margin: 0; + } + + a { + @extend .link-underline; + } + + .thin-bottom::after { + content: ""; + padding-bottom: 50px; + border-bottom: 1px solid #000; + width: 90px; + display: block; + margin: 0 auto; + } + +} From 9bb059c4ad463e1747db610aedb4374bf043700a Mon Sep 17 00:00:00 2001 From: Alexey Bobyrev Date: Fri, 23 Dec 2016 13:42:58 +0200 Subject: [PATCH 10/17] Catch errors with custom error pages yielded w/ application layout --- app/controllers/application_controller.rb | 1 + app/controllers/concerns/errors.rb | 36 +++++++++++ app/controllers/errors_controller.rb | 8 --- .../products/collections_controller.rb | 2 +- .../spree/omniauth_callbacks_controller.rb | 2 +- app/helpers/errors_helper.rb | 2 - app/views/errors/404.html.slim | 13 ++++ app/views/errors/422.html.slim | 13 ++++ app/views/errors/500.html.slim | 17 +++++ ...l.slim => _analytics_javascript.html.slim} | 13 +--- config/application.rb | 3 - config/routes.rb | 6 -- public/422.html | 26 -------- public/500.html | 64 ------------------- .../products/collections_controller_spec.rb | 2 +- 15 files changed, 86 insertions(+), 122 deletions(-) create mode 100644 app/controllers/concerns/errors.rb delete mode 100644 app/controllers/errors_controller.rb delete mode 100644 app/helpers/errors_helper.rb create mode 100644 app/views/errors/404.html.slim create mode 100644 app/views/errors/422.html.slim create mode 100644 app/views/errors/500.html.slim rename app/views/errors/{not_found.html.slim => _analytics_javascript.html.slim} (56%) delete mode 100644 public/422.html delete mode 100644 public/500.html diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 96ac84e399..2bbf1ca2c8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base include Concerns::UserCampaignable include Concerns::AutomaticDiscount include Concerns::Moodboards + include Concerns::Errors # Marketing related concerns include Marketing::Gtm::Controller::Container diff --git a/app/controllers/concerns/errors.rb b/app/controllers/concerns/errors.rb new file mode 100644 index 0000000000..1d3dfad4f9 --- /dev/null +++ b/app/controllers/concerns/errors.rb @@ -0,0 +1,36 @@ +module Concerns + module Errors + extend ActiveSupport::Concern + + included do + rescue_from ActiveRecord::RecordNotFound, with: :render_404 + rescue_from ActionController::UnknownController, with: :render_404 + rescue_from ActionController::UnknownAction, with: :render_404 + rescue_from ActiveRecord::RecordInvalid, with: :render_422 + rescue_from Exception, with: :render_500 + end + + protected + + def render_404 + render_error(code: 404) + end + + def render_422 + render_error(code: 422) + end + + def render_500 + render_error(code: 500) + end + + def render_error(code: 404) + respond_to do |format| + format.html { render "errors/#{code}", status: code } + format.xml { render nothing: true, status: code } + format.json { render nothing: true, status: code } + end + end + + end +end diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb deleted file mode 100644 index 16dba8f831..0000000000 --- a/app/controllers/errors_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class ErrorsController < ApplicationController - def not_found - render(:status => 404) - end - - def internal_server_error - end -end diff --git a/app/controllers/products/collections_controller.rb b/app/controllers/products/collections_controller.rb index 238bfc93f3..e25dc1f284 100644 --- a/app/controllers/products/collections_controller.rb +++ b/app/controllers/products/collections_controller.rb @@ -114,7 +114,7 @@ def collection_template if page.page_is_lookbook? || @collection_options page.template_path else - {file: 'public/404', layout: false, status: :not_found} + raise ActiveRecord::RecordNotFound end end diff --git a/app/controllers/spree/omniauth_callbacks_controller.rb b/app/controllers/spree/omniauth_callbacks_controller.rb index 306476432c..1fb01baecb 100644 --- a/app/controllers/spree/omniauth_callbacks_controller.rb +++ b/app/controllers/spree/omniauth_callbacks_controller.rb @@ -140,7 +140,7 @@ def failure end def passthru - render :file => "#{Rails.root}/public/404", :formats => [:html], :status => 404, :layout => false + raise ActiveRecord::RecordNotFound end def auth_hash diff --git a/app/helpers/errors_helper.rb b/app/helpers/errors_helper.rb deleted file mode 100644 index 8e3b415c57..0000000000 --- a/app/helpers/errors_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ErrorsHelper -end diff --git a/app/views/errors/404.html.slim b/app/views/errors/404.html.slim new file mode 100644 index 0000000000..05658eded9 --- /dev/null +++ b/app/views/errors/404.html.slim @@ -0,0 +1,13 @@ +- @title = "The page you were looking for doesn't exist (404)" + += render 'errors/analytics_javascript', locals: { code: 404, message: 'not found'} + +.error-page.text-center + h1 + | Looking for something? + h2 + | Sorry, this page doesn't exist. + p + | Try our #{link_to "homepage", root_path} to see what's new and start customizing. + p.thin-bottom + | Still can't find what you're looking for? #{link_to "E-mail us", 'mailto:team@fameandpartners.com'} at team@fameandpartners.com. diff --git a/app/views/errors/422.html.slim b/app/views/errors/422.html.slim new file mode 100644 index 0000000000..e43431f0d8 --- /dev/null +++ b/app/views/errors/422.html.slim @@ -0,0 +1,13 @@ +- @title = "The change you wanted was rejected (422)" + += render 'errors/analytics_javascript', locals: { code: 422, message: 'unprocessable entity'} + +.error-page.text-center + h1 + | The change you wanted was rejected. + h2 + | Maybe you tried to change something you didn't have access to. + p.thin-bottom + = link_to 'Go to homepage', root_path + p.thin-bottom + | Still can't find what you're looking for? #{link_to "E-mail us", 'mailto:team@fameandpartners.com'} at team@fameandpartners.com. diff --git a/app/views/errors/500.html.slim b/app/views/errors/500.html.slim new file mode 100644 index 0000000000..c0110f7d08 --- /dev/null +++ b/app/views/errors/500.html.slim @@ -0,0 +1,17 @@ +- @title = "We're sorry, but something went wrong (500)" + += render 'errors/analytics_javascript', locals: { code: 500, message: 'server error'} + +.error-page.text-center + h1 + | So sorry to interrupt your shopping experience. + p + | In the meantime, here is a $20 voucher to make up for your time - just use this code @checkout: OOPS20

+ p + | We should be back up in a few minutes but if you would like some further assistance, feel free to email or call us: + p + = link_to 'team@fameandpartners.com', 'mailto:team@fameandpartners.com' + p + | Our site engineers are currently making some upgrades to make it even better. + p.thin-bottom + = link_to 'Go to homepage', root_path diff --git a/app/views/errors/not_found.html.slim b/app/views/errors/_analytics_javascript.html.slim similarity index 56% rename from app/views/errors/not_found.html.slim rename to app/views/errors/_analytics_javascript.html.slim index 4365afe0cc..4723f31529 100644 --- a/app/views/errors/not_found.html.slim +++ b/app/views/errors/_analytics_javascript.html.slim @@ -1,12 +1,5 @@ -.error-page.text-center - h1 - | Looking for something? - h2 - | Sorry, this page doesn't exist. - p - | Try our #{link_to "homepage", '/'} to see what's new and start customizing. - p.thin-bottom - | Still can't find what you're looking for? #{link_to "E-mail us", 'mailto:team@fameandpartners.com'} at team@fameandpartners.com. +- code = local_assigns[:code] +- message = local_assigns[:message] javascript: (function (i, s, o, g, r, a, m) { @@ -22,4 +15,4 @@ javascript: })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); ga('create', 'UA-41247818-1', 'auto'); ga('send', 'pageview'); - ga('send', 'event', '404', 'not found'); + ga('send', 'event', "#{code}", "#{message}"); diff --git a/config/application.rb b/config/application.rb index 4e68cf7a32..f4be33c31b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -119,9 +119,6 @@ class Application < Rails::Application config.skip_mail_delivery = false - #Use route for error handling - config.exceptions_app = self.routes - config.generators do |generator| generator.test_framework :rspec end diff --git a/config/routes.rb b/config/routes.rb index 2c47655bcd..381c177e97 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -424,12 +424,6 @@ mount Spree::Core::Engine, at: '/' - ######## - # 404 Error Pages - ######## - - get "/404", :to => "errors#not_found", :via => :all - ############################################ # Storefront (Search, Checkout and Payments) ############################################ diff --git a/public/422.html b/public/422.html deleted file mode 100644 index 83660ab187..0000000000 --- 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 9b0f5aea3d..0000000000 --- a/public/500.html +++ /dev/null @@ -1,64 +0,0 @@ - - - - We're sorry, but something went wrong (500) - - - - - -
- -

So sorry to interrupt your shopping experience.

-

In the meantime, here is a $20 voucher to make up for your time - just use this code @checkout: OOPS20

-

- We should be back up in a few minutes but if you would like some further assistance, feel free to email or call us: -

-

- team@fameandpartners.com -

-
- Our site engineers are currently making some upgrades to make it even better. -
-

- Go to the homepage -

-
-
- ::CLOUDFLARE_ERROR_500S_BOX:: -
- - - diff --git a/spec/controllers/products/collections_controller_spec.rb b/spec/controllers/products/collections_controller_spec.rb index 750067d079..be3ab2b9be 100644 --- a/spec/controllers/products/collections_controller_spec.rb +++ b/spec/controllers/products/collections_controller_spec.rb @@ -47,7 +47,7 @@ it 'when querying a inexistent permalink' do get :show, permalink: 'nothing' - expect(response).to render_template(file: 'public/404', layout: false) + expect(response).to render_template(file: 'errors/404', layout: 'redesign/application') expect(response).to have_http_status(:not_found) end end From 0e6dbf873dd879de020f09224ee57f1144a24774 Mon Sep 17 00:00:00 2001 From: Alexey Bobyrev Date: Thu, 29 Dec 2016 18:50:09 +0200 Subject: [PATCH 11/17] Optimize calls + raise exception for development mode --- app/controllers/concerns/errors.rb | 36 ++++++++----------- .../products/collections_controller_spec.rb | 1 + 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/app/controllers/concerns/errors.rb b/app/controllers/concerns/errors.rb index 1d3dfad4f9..075d5bbc28 100644 --- a/app/controllers/concerns/errors.rb +++ b/app/controllers/concerns/errors.rb @@ -3,32 +3,24 @@ module Errors extend ActiveSupport::Concern included do - rescue_from ActiveRecord::RecordNotFound, with: :render_404 - rescue_from ActionController::UnknownController, with: :render_404 - rescue_from ActionController::UnknownAction, with: :render_404 - rescue_from ActiveRecord::RecordInvalid, with: :render_422 - rescue_from Exception, with: :render_500 + rescue_from Exception, with: -> { render_error(code: 500) } + rescue_from ActiveRecord::RecordInvalid, with: -> { render_error(code: 422) } + rescue_from ActiveRecord::RecordNotFound, with: -> { render_error(code: 404) } + rescue_from ActionController::UnknownController, with: -> { render_error(code: 404) } + rescue_from ActionController::UnknownAction, with: -> { render_error(code: 404) } + rescue_from ActionController::RoutingError, with: -> { render_error(code: 404) } end protected - def render_404 - render_error(code: 404) - end - - def render_422 - render_error(code: 422) - end - - def render_500 - render_error(code: 500) - end - - def render_error(code: 404) - respond_to do |format| - format.html { render "errors/#{code}", status: code } - format.xml { render nothing: true, status: code } - format.json { render nothing: true, status: code } + def render_error(code:) + if Rails.application.config.consider_all_requests_local + raise + else + respond_to do |format| + format.html { render "errors/#{code}", status: code } + format.all { render nothing: true, status: code } + end end end diff --git a/spec/controllers/products/collections_controller_spec.rb b/spec/controllers/products/collections_controller_spec.rb index be3ab2b9be..73385eadbe 100644 --- a/spec/controllers/products/collections_controller_spec.rb +++ b/spec/controllers/products/collections_controller_spec.rb @@ -43,6 +43,7 @@ describe 'returns a 404 status' do before(:each) do allow(controller).to receive(:parse_permalink).and_return(nil) + allow(Rails.application.config).to receive(:consider_all_requests_local).and_return(false) end it 'when querying a inexistent permalink' do From 4d06368af0c4433051a4b80c3fda983e6c904296 Mon Sep 17 00:00:00 2001 From: Mateus Moraes Date: Thu, 29 Dec 2016 17:20:32 -0200 Subject: [PATCH 12/17] update styling and put content inside .container --- app/assets/stylesheets/redesign/_error.scss | 11 +------- .../redesign/generic/_helpers.scss | 16 +++++++++++ .../stylesheets/redesign/pages/_why-us.scss | 8 ++---- app/views/errors/404.html.slim | 20 +++++++------ app/views/errors/422.html.slim | 20 +++++++------ app/views/errors/500.html.slim | 28 ++++++++++--------- 6 files changed, 56 insertions(+), 47 deletions(-) diff --git a/app/assets/stylesheets/redesign/_error.scss b/app/assets/stylesheets/redesign/_error.scss index 8335fad7e2..5fa9ffca7f 100644 --- a/app/assets/stylesheets/redesign/_error.scss +++ b/app/assets/stylesheets/redesign/_error.scss @@ -1,4 +1,4 @@ -// 404 - 500 Pages +// Error Pages (Errors 404, 500 etc) .error-page { margin: 100px auto; @@ -23,13 +23,4 @@ @extend .link-underline; } - .thin-bottom::after { - content: ""; - padding-bottom: 50px; - border-bottom: 1px solid #000; - width: 90px; - display: block; - margin: 0 auto; - } - } diff --git a/app/assets/stylesheets/redesign/generic/_helpers.scss b/app/assets/stylesheets/redesign/generic/_helpers.scss index 774959717c..cd96132d5c 100644 --- a/app/assets/stylesheets/redesign/generic/_helpers.scss +++ b/app/assets/stylesheets/redesign/generic/_helpers.scss @@ -202,6 +202,22 @@ } +.thin-line { + + &--bottom::after { + content: ""; + padding-bottom: 50px; + border-bottom: 1px solid $c-neutral-black; + width: 90px; + display: block; + } + + &--alignCenter::after { + margin: 0 auto; + } + +} + @media (min-width: $bootstrap-md-width) { .no-margin-md { diff --git a/app/assets/stylesheets/redesign/pages/_why-us.scss b/app/assets/stylesheets/redesign/pages/_why-us.scss index 30d4d6e2b4..1ba2cca66f 100644 --- a/app/assets/stylesheets/redesign/pages/_why-us.scss +++ b/app/assets/stylesheets/redesign/pages/_why-us.scss @@ -33,12 +33,8 @@ } .heading-thin-line-bottom::after { - content: ""; - padding-bottom: 40px; + @extend .thin-line--bottom; margin-bottom: 40px; - border-bottom: 1px solid $c-neutral-black; - width: 90px; - display: block; } @media (max-width: $bootstrap-md-width - 1px) { @@ -63,7 +59,7 @@ } } - + } } diff --git a/app/views/errors/404.html.slim b/app/views/errors/404.html.slim index 05658eded9..c3e8480e15 100644 --- a/app/views/errors/404.html.slim +++ b/app/views/errors/404.html.slim @@ -2,12 +2,14 @@ = render 'errors/analytics_javascript', locals: { code: 404, message: 'not found'} -.error-page.text-center - h1 - | Looking for something? - h2 - | Sorry, this page doesn't exist. - p - | Try our #{link_to "homepage", root_path} to see what's new and start customizing. - p.thin-bottom - | Still can't find what you're looking for? #{link_to "E-mail us", 'mailto:team@fameandpartners.com'} at team@fameandpartners.com. +.container + .col-xs-12 + .error-page.text-center + h1 + | Looking for something? + h2 + | Sorry, this page doesn't exist. + p + | Try our #{link_to "homepage", root_path} to see what's new and start customizing. + p.thin-line--bottom.thin-line--alignCenter + | Still can't find what you're looking for? #{link_to "E-mail us", 'mailto:team@fameandpartners.com'} at team@fameandpartners.com. diff --git a/app/views/errors/422.html.slim b/app/views/errors/422.html.slim index e43431f0d8..ad0cc64e2a 100644 --- a/app/views/errors/422.html.slim +++ b/app/views/errors/422.html.slim @@ -2,12 +2,14 @@ = render 'errors/analytics_javascript', locals: { code: 422, message: 'unprocessable entity'} -.error-page.text-center - h1 - | The change you wanted was rejected. - h2 - | Maybe you tried to change something you didn't have access to. - p.thin-bottom - = link_to 'Go to homepage', root_path - p.thin-bottom - | Still can't find what you're looking for? #{link_to "E-mail us", 'mailto:team@fameandpartners.com'} at team@fameandpartners.com. +.container + .col-xs-12 + .error-page.text-center + h1 + | The change you wanted was rejected. + h2 + | Maybe you tried to change something you didn't have access to. + p + | Try our #{link_to "homepage", root_path} to see what's new and start customizing. + p.thin-line--bottom.thin-line--alignCenter + | Still can't find what you're looking for? #{link_to "E-mail us", 'mailto:team@fameandpartners.com'} at team@fameandpartners.com. diff --git a/app/views/errors/500.html.slim b/app/views/errors/500.html.slim index c0110f7d08..79cf1ecfa7 100644 --- a/app/views/errors/500.html.slim +++ b/app/views/errors/500.html.slim @@ -2,16 +2,18 @@ = render 'errors/analytics_javascript', locals: { code: 500, message: 'server error'} -.error-page.text-center - h1 - | So sorry to interrupt your shopping experience. - p - | In the meantime, here is a $20 voucher to make up for your time - just use this code @checkout: OOPS20

- p - | We should be back up in a few minutes but if you would like some further assistance, feel free to email or call us: - p - = link_to 'team@fameandpartners.com', 'mailto:team@fameandpartners.com' - p - | Our site engineers are currently making some upgrades to make it even better. - p.thin-bottom - = link_to 'Go to homepage', root_path +.container + .col-xs-12 + .error-page.text-center + h1 + | So sorry to interrupt your shopping experience. + p + | In the meantime, here is a $20 voucher to make up for your time - just use this code @checkout: OOPS20

+ p + | We should be back up in a few minutes but if you would like some further assistance, feel free to email or call us: + p + = link_to 'team@fameandpartners.com', 'mailto:team@fameandpartners.com' + p + | Our site engineers are currently making some upgrades to make it even better. + p.thin-line--bottom.thin-line--alignCenter + = link_to 'Go to homepage', root_path From d5f749276dd08a2c1174b221ef070bb03ea72231 Mon Sep 17 00:00:00 2001 From: Alexey Bobyrev Date: Wed, 11 Jan 2017 12:22:45 +0200 Subject: [PATCH 13/17] Return back static 500 page --- app/controllers/concerns/errors.rb | 1 - app/views/errors/500.html.slim | 19 --------- public/500.html | 64 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 20 deletions(-) delete mode 100644 app/views/errors/500.html.slim create mode 100644 public/500.html diff --git a/app/controllers/concerns/errors.rb b/app/controllers/concerns/errors.rb index 075d5bbc28..c860fef302 100644 --- a/app/controllers/concerns/errors.rb +++ b/app/controllers/concerns/errors.rb @@ -3,7 +3,6 @@ module Errors extend ActiveSupport::Concern included do - rescue_from Exception, with: -> { render_error(code: 500) } rescue_from ActiveRecord::RecordInvalid, with: -> { render_error(code: 422) } rescue_from ActiveRecord::RecordNotFound, with: -> { render_error(code: 404) } rescue_from ActionController::UnknownController, with: -> { render_error(code: 404) } diff --git a/app/views/errors/500.html.slim b/app/views/errors/500.html.slim deleted file mode 100644 index 79cf1ecfa7..0000000000 --- a/app/views/errors/500.html.slim +++ /dev/null @@ -1,19 +0,0 @@ -- @title = "We're sorry, but something went wrong (500)" - -= render 'errors/analytics_javascript', locals: { code: 500, message: 'server error'} - -.container - .col-xs-12 - .error-page.text-center - h1 - | So sorry to interrupt your shopping experience. - p - | In the meantime, here is a $20 voucher to make up for your time - just use this code @checkout: OOPS20

- p - | We should be back up in a few minutes but if you would like some further assistance, feel free to email or call us: - p - = link_to 'team@fameandpartners.com', 'mailto:team@fameandpartners.com' - p - | Our site engineers are currently making some upgrades to make it even better. - p.thin-line--bottom.thin-line--alignCenter - = link_to 'Go to homepage', root_path diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000000..9b0f5aea3d --- /dev/null +++ b/public/500.html @@ -0,0 +1,64 @@ + + + + We're sorry, but something went wrong (500) + + + + + +
+ +

So sorry to interrupt your shopping experience.

+

In the meantime, here is a $20 voucher to make up for your time - just use this code @checkout: OOPS20

+

+ We should be back up in a few minutes but if you would like some further assistance, feel free to email or call us: +

+

+ team@fameandpartners.com +

+
+ Our site engineers are currently making some upgrades to make it even better. +
+

+ Go to the homepage +

+
+
+ ::CLOUDFLARE_ERROR_500S_BOX:: +
+ + + From 89c8e57fa6f5a2c04bb54ee0ac5206093353c806 Mon Sep 17 00:00:00 2001 From: Alexey Bobyrev Date: Sat, 14 Jan 2017 03:10:15 +0200 Subject: [PATCH 14/17] Make rails app available to catch RoutingError (raised by ActionDispatch) Ref: https://github.com/rails/rails/issues/671 --- app/controllers/concerns/errors.rb | 7 +++++++ config/routes.rb | 3 +++ 2 files changed, 10 insertions(+) diff --git a/app/controllers/concerns/errors.rb b/app/controllers/concerns/errors.rb index c860fef302..aec42bfc5a 100644 --- a/app/controllers/concerns/errors.rb +++ b/app/controllers/concerns/errors.rb @@ -10,6 +10,13 @@ module Errors rescue_from ActionController::RoutingError, with: -> { render_error(code: 404) } end + # NOTE: Alexey Bobyrev 14 Jan 2017 + # Raise error here to make it visible for application#rescue_from + # Ref: https://github.com/rails/rails/issues/671 + def raise_routing_error + raise ActionController::RoutingError.new(params[:path]) + end + protected def render_error(code:) diff --git a/config/routes.rb b/config/routes.rb index 381c177e97..d2db3cf896 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -626,4 +626,7 @@ mount WeddingAtelier::Engine, at: '/wedding-atelier' match '*path', to: 'errors/invalid_format#capture_php', constraints: lambda { |request| request.path[/\.php$/] } + # NOTE: Alexey Bobyrev 14 Jan 2017 + # Any other routes are handled here (as ActionDispatch prevents RoutingError from hitting ApplicationController::rescue_action) + match '*path', to: 'application#raise_routing_error' end From bf0a952d2bee70af2a98d0750928f72bd63a4281 Mon Sep 17 00:00:00 2001 From: Alexey Bobyrev Date: Sat, 14 Jan 2017 12:29:40 +0200 Subject: [PATCH 15/17] Fix not found routes spec --- app/controllers/concerns/errors.rb | 2 +- spec/routing/not_found_routes_spec.rb | 23 +++++++++++++++++++++++ spec/routing/route_php_spec.rb | 16 ---------------- 3 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 spec/routing/not_found_routes_spec.rb delete mode 100644 spec/routing/route_php_spec.rb diff --git a/app/controllers/concerns/errors.rb b/app/controllers/concerns/errors.rb index aec42bfc5a..e69cd3cb17 100644 --- a/app/controllers/concerns/errors.rb +++ b/app/controllers/concerns/errors.rb @@ -6,8 +6,8 @@ module Errors rescue_from ActiveRecord::RecordInvalid, with: -> { render_error(code: 422) } rescue_from ActiveRecord::RecordNotFound, with: -> { render_error(code: 404) } rescue_from ActionController::UnknownController, with: -> { render_error(code: 404) } - rescue_from ActionController::UnknownAction, with: -> { render_error(code: 404) } rescue_from ActionController::RoutingError, with: -> { render_error(code: 404) } + rescue_from AbstractController::ActionNotFound, with: -> { render_error(code: 404) } end # NOTE: Alexey Bobyrev 14 Jan 2017 diff --git a/spec/routing/not_found_routes_spec.rb b/spec/routing/not_found_routes_spec.rb new file mode 100644 index 0000000000..18bc329e47 --- /dev/null +++ b/spec/routing/not_found_routes_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe 'Not found requests', type: :routing do + describe 'with *.php' do + let(:controller) { {controller: 'errors/invalid_format', action: 'capture_php', path: 'abc', format: 'php'} } + + it 'routes to errors/invalid_format#capture_php' do + expect(get: '/abc.php').to route_to(controller) + expect(post: '/abc.php').to route_to(controller) + end + end + + describe 'with any non-existent page' do + let(:controller) { {controller: 'application', action: 'raise_routing_error', path: 'abc'} } + + it 'rotes to application#raise_routing_error' do + expect(get: '/abc').to route_to(controller) + expect(post: '/abc').to route_to(controller) + expect(get: '/abc.js').to route_to(controller.merge(format: 'js')) + end + end + +end diff --git a/spec/routing/route_php_spec.rb b/spec/routing/route_php_spec.rb deleted file mode 100644 index 576d3100d4..0000000000 --- a/spec/routing/route_php_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'spec_helper' - -describe 'Route `.php` requests', type: :routing do - let(:controller) { {controller: 'errors/invalid_format', action: 'capture_php', path: 'abc', format: 'php'} } - - it 'routes to errors/invalid_format#capture_php' do - expect(get: '/abc.php').to route_to(controller) - expect(post: '/abc.php').to route_to(controller) - end - - it 'should not route' do - expect(get: '/abc').not_to be_routable - expect(post: '/abc').not_to be_routable - expect(get: '/abc.js').not_to be_routable - end -end From ab239d54f5e3f6e2e8e1b05347d29495e2c75869 Mon Sep 17 00:00:00 2001 From: Alexey Bobyrev Date: Thu, 16 Feb 2017 11:08:24 -0800 Subject: [PATCH 16/17] Fix unmactched routes catch --- app/controllers/concerns/errors.rb | 25 ++++++++++++--- .../errors/invalid_format_controller.rb | 9 ------ .../errors/mysterious_route_controller.rb | 14 --------- config/routes.rb | 18 ++++------- .../mysterious_route_controller_spec.rb | 27 ---------------- spec/routing/not_found_routes_spec.rb | 31 +++++++++++++------ 6 files changed, 47 insertions(+), 77 deletions(-) delete mode 100644 app/controllers/errors/invalid_format_controller.rb delete mode 100644 app/controllers/errors/mysterious_route_controller.rb delete mode 100644 spec/controllers/mysterious_route_controller_spec.rb diff --git a/app/controllers/concerns/errors.rb b/app/controllers/concerns/errors.rb index e69cd3cb17..ffade8792c 100644 --- a/app/controllers/concerns/errors.rb +++ b/app/controllers/concerns/errors.rb @@ -2,6 +2,8 @@ module Concerns module Errors extend ActiveSupport::Concern + MYSTERIOUS_ROUTES = [ 'undefined', '/au/undefined', '1000668' ].freeze + included do rescue_from ActiveRecord::RecordInvalid, with: -> { render_error(code: 422) } rescue_from ActiveRecord::RecordNotFound, with: -> { render_error(code: 404) } @@ -10,11 +12,24 @@ module Errors rescue_from AbstractController::ActionNotFound, with: -> { render_error(code: 404) } end - # NOTE: Alexey Bobyrev 14 Jan 2017 - # Raise error here to make it visible for application#rescue_from - # Ref: https://github.com/rails/rails/issues/671 - def raise_routing_error - raise ActionController::RoutingError.new(params[:path]) + def non_matching_request + path = params.fetch(:path, '') + format = params.fetch(:format, '') + + if path.match(/\.php$/) || format.eql?('php') + head :not_acceptable, layout: false + + elsif MYSTERIOUS_ROUTES.any? { |v| v.match(path) } + data = request.env.select {|key,_| key.upcase == key } + NewRelic::Agent.record_custom_event('UndefinedURL', data) + render text: 'Not Found', status: :not_found + + else + # NOTE: Alexey Bobyrev 14 Jan 2017 + # Raise error here to make it visible for application#rescue_from + # Ref: https://github.com/rails/rails/issues/671 + raise ActionController::RoutingError.new(path) + end end protected diff --git a/app/controllers/errors/invalid_format_controller.rb b/app/controllers/errors/invalid_format_controller.rb deleted file mode 100644 index 743ac229fe..0000000000 --- a/app/controllers/errors/invalid_format_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Errors - class InvalidFormatController < ActionController::Base - layout false - - def capture_php - head :not_acceptable - end - end -end diff --git a/app/controllers/errors/mysterious_route_controller.rb b/app/controllers/errors/mysterious_route_controller.rb deleted file mode 100644 index 3de9e5ecc9..0000000000 --- a/app/controllers/errors/mysterious_route_controller.rb +++ /dev/null @@ -1,14 +0,0 @@ -module Errors - class MysteriousRouteController < ActionController::Base - layout false - - # Captures and logs hits to weird URLs we keep seeing in the logs. - # '/undefined' '/au/undefined' - def undefined - data = request.env.select {|key,_| key.upcase == key } - - NewRelic::Agent.record_custom_event("UndefinedURL", data) - render :text => 'Not Found', :status => :not_found - end - end -end diff --git a/config/routes.rb b/config/routes.rb index d2db3cf896..95c07173f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,4 @@ FameAndPartners::Application.routes.draw do - ############################ # Devise Omniauth Workaround ############################ @@ -503,14 +502,6 @@ end end - ################# - # Mysterious URLs - ################# - - get '/undefined', to: 'errors/mysterious_route#undefined' - get '/au/undefined', to: 'errors/mysterious_route#undefined' - get '/1000668', to: 'errors/mysterious_route#undefined' - ######### # Widgets ######### @@ -624,9 +615,12 @@ mount Revolution::Engine => '/' mount WeddingAtelier::Engine, at: '/wedding-atelier' +end - match '*path', to: 'errors/invalid_format#capture_php', constraints: lambda { |request| request.path[/\.php$/] } +# NOTE: Alexey Bobyrev 14 Feb 2017 +# Method append used here to handle all request directly right after defined ones (including engines) +FameAndPartners::Application.routes.append do # NOTE: Alexey Bobyrev 14 Jan 2017 - # Any other routes are handled here (as ActionDispatch prevents RoutingError from hitting ApplicationController::rescue_action) - match '*path', to: 'application#raise_routing_error' + # Any other routes are handled here (as ActionDispatch prevents RoutingError from hitting ApplicationController#rescue_action) + match '*path', to: 'application#non_matching_request', as: 'routing_error' end diff --git a/spec/controllers/mysterious_route_controller_spec.rb b/spec/controllers/mysterious_route_controller_spec.rb deleted file mode 100644 index 67a71a202d..0000000000 --- a/spec/controllers/mysterious_route_controller_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'rails_helper' - -RSpec.describe Errors::MysteriousRouteController, type: :controller do - describe "GET #undefined" do - it "returns not found" do - get :undefined - expect(response).to have_http_status(:not_found) - end - end -end - -RSpec.describe Errors::MysteriousRouteController, type: :routing do - - let(:controller) { { controller: 'errors/mysterious_route', action: 'undefined'} } - - it "/undefined" do - expect(get: "/undefined").to route_to(controller) - end - - it "/au/undefined" do - expect(get: "/au/undefined").to route_to(controller) - end - - it "/1000668'" do - expect(get: '/1000668').to route_to(controller) - end -end diff --git a/spec/routing/not_found_routes_spec.rb b/spec/routing/not_found_routes_spec.rb index 18bc329e47..8a8b0e287f 100644 --- a/spec/routing/not_found_routes_spec.rb +++ b/spec/routing/not_found_routes_spec.rb @@ -1,22 +1,33 @@ require 'spec_helper' -describe 'Not found requests', type: :routing do +describe 'Not found requests', type: :request do + describe 'with *.php' do - let(:controller) { {controller: 'errors/invalid_format', action: 'capture_php', path: 'abc', format: 'php'} } + it 'routes to application#non_matching_request' do + get '/abc.php' - it 'routes to errors/invalid_format#capture_php' do - expect(get: '/abc.php').to route_to(controller) - expect(post: '/abc.php').to route_to(controller) + expect(response).to render_template(nil) + expect(response).to have_http_status(406) end end describe 'with any non-existent page' do - let(:controller) { {controller: 'application', action: 'raise_routing_error', path: 'abc'} } + it 'rotes to application#non_matching_request' do + get '/abc' + + expect(response.body).to match("this page doesn't exist") + expect(response.body).to match('MY ACCOUNT') + expect(response.body).to match('Fame & Partners. All rights reserved.') + expect(response).to have_http_status(404) + end + end + + describe 'with an undefined page' do + it 'rotes to application#non_matching_request' do + get '/undefined' - it 'rotes to application#raise_routing_error' do - expect(get: '/abc').to route_to(controller) - expect(post: '/abc').to route_to(controller) - expect(get: '/abc.js').to route_to(controller.merge(format: 'js')) + expect(response.body).to match('Not Found') + expect(response).to have_http_status(404) end end From 62843b23da4bf39cb2e8ca1f5fd0042a618d3743 Mon Sep 17 00:00:00 2001 From: Alexey Bobyrev Date: Thu, 16 Feb 2017 18:11:21 -0800 Subject: [PATCH 17/17] Fix specs --- spec/routing/not_found_routes_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/routing/not_found_routes_spec.rb b/spec/routing/not_found_routes_spec.rb index 8a8b0e287f..4899fa0c4c 100644 --- a/spec/routing/not_found_routes_spec.rb +++ b/spec/routing/not_found_routes_spec.rb @@ -2,17 +2,19 @@ describe 'Not found requests', type: :request do - describe 'with *.php' do - it 'routes to application#non_matching_request' do + describe 'routes to application#non_matching_request' do + before(:each) do + allow(Rails.application.config).to receive(:consider_all_requests_local).and_return(false) + end + + it 'with *.php' do get '/abc.php' expect(response).to render_template(nil) expect(response).to have_http_status(406) end - end - describe 'with any non-existent page' do - it 'rotes to application#non_matching_request' do + it 'with any non-existent page' do get '/abc' expect(response.body).to match("this page doesn't exist") @@ -20,10 +22,8 @@ expect(response.body).to match('Fame & Partners. All rights reserved.') expect(response).to have_http_status(404) end - end - describe 'with an undefined page' do - it 'rotes to application#non_matching_request' do + it 'with an undefined page' do get '/undefined' expect(response.body).to match('Not Found')