Skip to content

Commit

Permalink
Don't use legacy layouts for errors (#2517)
Browse files Browse the repository at this point in the history
The error pages were using the legacy branding and this is very
confusing, especially when shown in the embedded contexts. This change
ensures the error pages are styled like regular pages.
  • Loading branch information
benlovell authored Jan 16, 2025
1 parent 088cd58 commit db77914
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 41 deletions.
37 changes: 32 additions & 5 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
class ErrorsController < ApplicationController
layout 'error'
class ErrorsController < EmbeddedToolsController
before_action :fetch_exception

layout 'engine_syndicated'

def show
render :show, status: params[:status_code], formats: [:html]
end

def display_skip_to_main_navigation?
params[:status_code] != '404'
private

def canonical
''
end
helper_method :canonical

private
def syndicated_tool_request?
true
end
helper_method :syndicated_tool_request?

def alternate_locale
nil
end
helper_method :alternate_locale

def alternate_options
{ 'en-GB' => request.url }
end
helper_method :alternate_options

def alternate_url
nil
end
helper_method :alternate_url

def engine_content?
true
end
helper_method :engine_content?

def fetch_exception
@exception = env['action_dispatch.exception']
Expand Down
29 changes: 7 additions & 22 deletions app/views/errors/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
<% set_meta_tags(title: t(".#{@rescue_response}.title")) %>

<%= heading_tag t(".#{@rescue_response}.heading", default: t('.heading')), class: "error-page__headline" %>

<p class="error-page__text<% if @rescue_response != :not_found %> error-page__text--only<% end %>"><%= t(".#{@rescue_response}.intro", default: t(".#{@rescue_response}.title")) %></p>

<p class="error-page__search-text"><%= t(".#{@rescue_response}.message") %></p>

<form data-dough-component="ClearInput" action="/en/search" method="get" role="search" class="error-page__search search">
<label class="visually-hidden" for="search"><%= t('search_box.label') %></label>
<input data-dough-clear-input class="search__input" id="search" required type="search" name="query" autocomplete="off" placeholder="<%= t(".#{@rescue_response}.search_placeholder") %>" />

<button data-dough-clear-input-button type="reset" class="search__clear">
<span class="icon icon--clear"></span>
<span class="visually-hidden"><%= t('search_box.clear_hidden_text') %></span>
</button>

<button class="search__submit" type="submit">
<span class="icon icon--search"></span>
<span class="visually-hidden"><%= t('search_box.button_text') %></span>
</button>
</form>
<% content_for(:engine_content) do %>
<div class="global-alert__content-container">
<%= heading_tag t(".#{@rescue_response}.heading", default: t('.heading')) %>
<p><%= t(".#{@rescue_response}.intro", default: t(".#{@rescue_response}.title")) %></p>
<p><%= t(".#{@rescue_response}.message") %></p>
</div>
<% end %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def not_implemented
get '/hub/:slug' => 'content_hub#show', as: :content_hub
end

%w(422 500 ).each do |status_code|
%w(422 500).each do |status_code|
get status_code, to: 'errors#show', status_code: status_code
end

Expand Down
13 changes: 0 additions & 13 deletions spec/views/errors/show_spec.rb

This file was deleted.

0 comments on commit db77914

Please sign in to comment.