-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error pages for unhandled exceptions (#269)
* Add error pages for unhandled exceptions https://eaflood.atlassian.net/browse/WC-308 If an error occurs, we don't want users to be kicked out to a scary or unclear error page. Instead, we should present a page which uses the same GOV.UK templates, explains an issue has occured and states what their next steps are. * Set up errors controller and pages The ErrorsController serves a specific page for the error if one exists, or a generic one if there is no match. This is based on the implementation from FRAE (https://github.com/DEFRA/flood-risk-engine/)
- Loading branch information
1 parent
ae7499f
commit 9ed1a21
Showing
12 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/controllers/waste_carriers_engine/errors_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module WasteCarriersEngine | ||
class ErrorsController < ApplicationController | ||
def show | ||
render( | ||
template: file_for(template), | ||
locals: { message: exception.try(:message) } | ||
) | ||
end | ||
|
||
protected | ||
|
||
def error_code | ||
@error_code ||= params[:id] | ||
end | ||
|
||
def template_exists(name) | ||
File.exist?(template_path(name)) | ||
end | ||
|
||
def template_path(name) | ||
File.expand_path( | ||
"app/views/#{file_for(name)}.html.erb", | ||
WasteCarriersEngine::Engine.root | ||
) | ||
end | ||
|
||
def template | ||
@template ||= template_exists(error_code) ? error_code : "generic" | ||
end | ||
|
||
def file_for(name) | ||
"waste_carriers_engine/errors/error_#{name}" | ||
end | ||
|
||
def exception | ||
env["action_dispatch.exception"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1 class="heading-large"> | ||
<%= t(".heading") %> | ||
</h1> | ||
|
||
<p><%= t(".sorry") %></p> | ||
<p><%= t(".clarification") %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1 class="heading-large"> | ||
<%= t(".heading") %> | ||
</h1> | ||
|
||
<p><%= t(".sorry") %></p> | ||
<p><%= t(".clarification") %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1 class="heading-large"> | ||
<%= t(".heading") %> | ||
</h1> | ||
|
||
<p><%= t(".sorry") %></p> | ||
<p><%= t(".clarification") %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1 class="heading-large"> | ||
<%= t(".heading") %> | ||
</h1> | ||
|
||
<p><%= t(".sorry") %></p> | ||
<p><%= t(".clarification") %></p> |
6 changes: 6 additions & 0 deletions
6
app/views/waste_carriers_engine/errors/error_generic.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1 class="heading-large"> | ||
<%= t(".heading") %> | ||
</h1> | ||
|
||
<p><%= t(".sorry") %></p> | ||
<p><%= t(".try_again") %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
unless Rails.application.config.consider_all_requests_local | ||
Rails.application.config.exceptions_app = WasteCarriersEngine::Engine.routes | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
en: | ||
waste_carriers_engine: | ||
errors: | ||
error_generic: | ||
heading: Something went wrong | ||
sorry: Sorry, there was a technical problem. It has been reported to our support team. | ||
clarification: If it happens again, call the Environment Agency helpline 03708 506 506. | ||
try_again: Please try again in a few minutes. | ||
error_401: | ||
heading: Unauthorised | ||
sorry: Sorry, you don't have permission to access this page. | ||
clarification: Please check the web address you entered is correct. | ||
error_403: | ||
# As per https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4 | ||
# We do not wish to make this information available to the client, therefore using messaging for 404-not-found instead. | ||
heading: Page not found | ||
sorry: Sorry, we can't find that page. | ||
clarification: Please check the web address you entered is correct. | ||
link: Start again | ||
error_404: | ||
heading: Page not found | ||
sorry: Sorry, we can't find that page. | ||
clarification: Please check the web address you entered was correct. | ||
link: Start again | ||
error_422: | ||
heading: There was a problem | ||
sorry: Sorry, the system wasn't able to complete that step. | ||
clarification: You could go back and try it again. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "rails_helper" | ||
|
||
module WasteCarriersEngine | ||
RSpec.describe "Errors", type: :request do | ||
describe "#show" do | ||
it "renders matching error template when one exists" do | ||
get error_path("401") | ||
expect(response).to render_template(:error_401) | ||
end | ||
|
||
it "renders generic error template when no matching error template exists" do | ||
get error_path("unknown") | ||
expect(response).to render_template(:error_generic) | ||
end | ||
end | ||
end | ||
end |