better error message if the localized 404 error page is missing (#57)
did
committed Feb 16, 2016
commit ee5b98ec8e5e276e1f2a57dbb6efd4a7d9436a63
Showing 3
changed files with
26 additions
and 4 deletions
locomotive/steam/middlewares/page.rb b/lib/locomotive/steam/middlewares/page.rb
+1
-0
| @@ | @@ -15,6 +15,7 @@ module Locomotive::Steam |
| if !page.not_found? | |
| log "Found page \"#{page.title}\" [#{page.fullpath}]" | |
| else | |
| + | ActiveSupport::Notifications.instrument('steam.render.page_not_found', path: path, locale: locale, default_locale: default_locale) |
| log "Page not found, rendering the 404 page.".magenta | |
| end | |
| end | |
locomotive/steam/middlewares/renderer.rb b/lib/locomotive/steam/middlewares/renderer.rb
+8
-2
| @@ | @@ -25,8 +25,14 @@ module Locomotive::Steam |
| end | |
| def render_missing_404 | |
| - | log "[Warning] Your 404 page is missing. Please create it.".red |
| - | render_response('Missing 404 page', 404) |
| + | message = (if locale != default_locale |
| + | "Your 404 page is missing in the #{locale} locale." |
| + | else |
| + | "Your 404 page is missing." |
| + | end) + " Please create it." |
| + | |
| + | log "[Warning] #{message}".red |
| + | render_response(message, 404) |
| end | |
| def parse_and_render_liquid | |
spec/unit/middlewares/renderer_spec.rb
+17
-2
| @@ | @@ -14,14 +14,29 @@ describe Locomotive::Steam::Middlewares::Renderer do |
| describe 'missing 404 page' do | |
| + | let(:locale) { 'en' } |
| + | let(:site) { instance_double('Site', default_locale: 'en') } |
| + | |
| subject do | |
| - | middleware.call env_for('http://www.example.com', { 'steam.page' => nil }) |
| + | middleware.call env_for('http://www.example.com', { 'steam.page' => nil, 'steam.locale' => locale, 'steam.site' => site }) |
| end | |
| specify 'return 200' do | |
| code, headers, response = subject | |
| expect(code).to eq(404) | |
| - | expect(response).to eq(['Missing 404 page']) |
| + | expect(response).to eq(["Your 404 page is missing. Please create it."]) |
| + | end |
| + | |
| + | context 'in another locale' do |
| + | |
| + | let(:locale) { 'fr' } |
| + | |
| + | specify 'return 200' do |
| + | code, headers, response = subject |
| + | expect(code).to eq(404) |
| + | expect(response).to eq(["Your 404 page is missing in the fr locale. Please create it."]) |
| + | end |
| + | |
| end | |
| end | |