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}" %> +
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 @@ - - - -You may have mistyped the address or the page may have moved.
-If you are the application owner check the logs for more information.
-Please upgrade your browser to continue.
-Maybe you tried to change something you didn't have access to.
-If you are the application owner check the logs for more information.
-If you are the application owner check the logs for more information.
-