Capture exception on sentry if something is wrong

This commit is contained in:
Mathieu Magnin 2024-11-12 13:32:49 +01:00
parent 1e7b5a56e4
commit 7fbe5dda98
No known key found for this signature in database
GPG key ID: 8DCAFC82D7BA654E
2 changed files with 11 additions and 1 deletions

View file

@ -1,7 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
class ErrorsController < ApplicationController 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) # 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 render file: Rails.public_path.join('500.html'), layout: false, status: :internal_server_error
end end

View file

@ -3,6 +3,15 @@
describe 'Errors handling', js: false do describe 'Errors handling', js: false do
let(:procedure) { create(:procedure) } 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 scenario 'bug renders dynamic 500 page' do
procedure.revisions.destroy_all # break procedure procedure.revisions.destroy_all # break procedure