diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index 4fa4b1e56..d82ca2e85 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -1,17 +1,34 @@ class ErrorsController < ApplicationController + layout 'errors' + + rescue_from StandardError, with: :handle_rendering_error + def forbidden - render status: :forbidden + render_error_page('errors/forbidden', :forbidden, '403 Forbidden') end def not_found - render status: :not_found + render_error_page('errors/not_found', :not_found, '404 Not Found') end def unacceptable - render status: :unprocessable_content + render_error_page('errors/unacceptable', :not_acceptable, '406 Not Acceptable') + end + + def unprocessable_entity + render_error_page('errors/unprocessable_entity', :unprocessable_entity, '422 Unprocessable Entity') end def internal_server_error - render status: :internal_server_error + render_error_page('errors/internal_server_error', :internal_server_error, '500 Internal Server Error') + end + + private + + def render_error_page(template, status, fallback_message) + render template: template, status: status + rescue StandardError => e + Rails.logger.error("Error rendering #{status} page: #{e.message}") + render plain: fallback_message, status: status end end diff --git a/app/views/errors/unprocessable_entity.html.erb b/app/views/errors/unprocessable_entity.html.erb new file mode 100644 index 000000000..811011cb7 --- /dev/null +++ b/app/views/errors/unprocessable_entity.html.erb @@ -0,0 +1,4 @@ +<% content_for :title, "Verzoek niet verwerkt (422) - #{Rails.application.config.x.site_name}" %> +

Verzoek niet verwerkt (422)

+

Je verzoek kon niet worden verwerkt. Dit komt meestal door ongeldige gegevens.

+

Controleer je invoer en probeer het opnieuw. Stuur een <%= link_to 'mailtje', "mailto:#{Rails.application.config.x.admin_email}" %> naar de ICT-commissie als dit probleem blijft optreden.

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 8838a243c..38875038f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,6 +65,7 @@ get '/403', to: 'errors#forbidden' get '/404', to: 'errors#not_found' - get '/422', to: 'errors#unacceptable' + get '/406', to: 'errors#unacceptable' + get '/422', to: 'errors#unprocessable_entity' get '/500', to: 'errors#internal_server_error' end diff --git a/public/404.html b/public/404.html deleted file mode 100644 index 2be3af26f..000000000 --- a/public/404.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - The page you were looking for doesn't exist (404) - - - - - - -
-
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html deleted file mode 100644 index 7cf1e168e..000000000 --- a/public/406-unsupported-browser.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - Your browser is not supported (406) - - - - - - -
-
-

Your browser is not supported.

-

Please upgrade your browser to continue.

-
-
- - diff --git a/public/422.html b/public/422.html deleted file mode 100644 index c08eac0d1..000000000 --- a/public/422.html +++ /dev/null @@ -1,67 +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.

-
-

If you are the application owner check the logs for more information.

-
- - diff --git a/public/500.html b/public/500.html deleted file mode 100644 index 78a030af2..000000000 --- a/public/500.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - We're sorry, but something went wrong (500) - - - - - - -
-
-

We're sorry, but something went wrong.

-
-

If you are the application owner check the logs for more information.

-
- -