diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c125850fc..21c76efd1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,8 +1,8 @@ class ApplicationController < ActionController::Base default_form_builder GOVUKDesignSystemFormBuilder::FormBuilder - def render_not_found_html - render file: Rails.root.join("public/404.html"), status: :not_found + def render_not_found + render "errors/not_found", status: :not_found end def render_not_found_json(class_name, id) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 59f91a6bf..b88425b54 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -55,7 +55,7 @@ class CaseLogsController < ApplicationController if @case_log render :edit else - render_not_found_html + render_not_found end end diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 000000000..6b5abfc42 --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,25 @@ +class ErrorsController < ApplicationController + skip_before_action :verify_authenticity_token + + def not_found + respond_to do |format| + format.html { render status: :not_found } + format.json { render json: { error: "Resource not found" }, status: :not_found } + format.all { render status: :not_found, body: nil } + end + end + + def internal_server_error + respond_to do |format| + format.html { render status: :internal_server_error } + format.json { render json: { error: "Internal server error" }, status: :internal_server_error } + end + end + + def unprocessable_entity + respond_to do |format| + format.html { render status: :unprocessable_entity } + format.json { render json: { error: "Unprocessable entity" }, status: :unprocessable_entity } + end + end +end diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 93dc32e84..5665731c7 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -16,7 +16,7 @@ class FormController < ApplicationController render "form/page", locals: { form: form, page: page, subsection: subsection.label }, status: :unprocessable_entity end else - render_not_found_html + render_not_found end end @@ -27,7 +27,7 @@ class FormController < ApplicationController subsection = form.get_subsection(current_url.split("/")[-2]) render "form/check_answers", locals: { subsection: subsection, form: form } else - render_not_found_html + render_not_found end end @@ -38,7 +38,7 @@ class FormController < ApplicationController subsection = form.subsection_for_page(page) render "form/page", locals: { form: form, page: page, subsection: subsection.label } else - render_not_found_html + render_not_found end end end diff --git a/public/422.html b/app/views/errors/internal_server_error.html.erb similarity index 50% rename from public/422.html rename to app/views/errors/internal_server_error.html.erb index 2d4d96440..03a7dab26 100644 --- a/public/422.html +++ b/app/views/errors/internal_server_error.html.erb @@ -1,6 +1,8 @@ +<% content_for :title, "Sorry, there is a problem with the service" %> +
Try again later.
If you typed the web address, check it is correct.
If you pasted the web address, check you copied the entire address.
Get help if the web address is correct and not working.
diff --git a/public/500.html b/app/views/errors/unprocessable_entity.html.erb similarity index 50% rename from public/500.html rename to app/views/errors/unprocessable_entity.html.erb index 2d4d96440..03a7dab26 100644 --- a/public/500.html +++ b/app/views/errors/unprocessable_entity.html.erb @@ -1,6 +1,8 @@ +<% content_for :title, "Sorry, there is a problem with the service" %> +Try again later.