From 7fbe5dda9840dffcd2392872b0fc3ae216eba8df Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 12 Nov 2024 13:32:49 +0100 Subject: [PATCH] Capture exception on sentry if something is wrong --- app/controllers/errors_controller.rb | 3 ++- spec/system/errors_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index dcdd1a7a5..79a394099 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class ErrorsController < ApplicationController - rescue_from Exception do + rescue_from StandardError do |exception| + Sentry.capture_exception(exception) # catch any error, except errors triggered by middlewares outside controller (like warden middleware) render file: Rails.public_path.join('500.html'), layout: false, status: :internal_server_error end diff --git a/spec/system/errors_spec.rb b/spec/system/errors_spec.rb index 553ab8e14..687291b61 100644 --- a/spec/system/errors_spec.rb +++ b/spec/system/errors_spec.rb @@ -3,6 +3,15 @@ describe 'Errors handling', js: false do let(:procedure) { create(:procedure) } + scenario 'not found returns 404' do + without_detailed_exceptions do + visit '/nonexistent-path' + end + + expect(page).to have_http_status(:not_found) + expect(page).to have_content('Page non trouvée') + end + scenario 'bug renders dynamic 500 page' do procedure.revisions.destroy_all # break procedure