File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
lib/rails_semantic_logger/extensions/action_dispatch Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -7,9 +7,11 @@ class DebugExceptions
77
88 undef_method :log_error
99 if ( Rails ::VERSION ::MAJOR == 7 && Rails ::VERSION ::MINOR >= 1 ) || Rails ::VERSION ::MAJOR > 7
10- def log_error ( _request , wrapper )
10+ def log_error ( request , wrapper )
1111 Rails . application . deprecators . silence do
12- level = wrapper . respond_to? ( :rescue_response? ) && wrapper . rescue_response? ? :debug : :fatal
12+ return if !log_rescued_responses? ( request ) && wrapper . rescue_response?
13+
14+ level = request . get_header ( "action_dispatch.debug_exception_log_level" )
1315 ActionController ::Base . logger . log ( level , wrapper . exception )
1416 end
1517 end
Original file line number Diff line number Diff line change @@ -141,6 +141,27 @@ class ArticlesControllerTest < ActionDispatch::IntegrationTest
141141 assert_equal 4 , messages . count , messages
142142 assert_kind_of ActiveRecord ::RecordNotFound , messages [ 3 ] . exception
143143 end
144+
145+ it "raises and does not log exception when action_dispatch.log_rescued_responses is false" do
146+ skip "Not applicable to older rails" if Rails . version . to_f < 7.1
147+ # we're testing ActionDispatch::DebugExceptions here too
148+ messages = semantic_logger_events do
149+ old_show = Rails . application . env_config [ "action_dispatch.show_exceptions" ]
150+ old_log_rescued_responses = Rails . application . env_config [ "action_dispatch.log_rescued_responses" ]
151+
152+ begin
153+ Rails . application . env_config [ "action_dispatch.show_exceptions" ] = :all
154+ Rails . application . env_config [ "action_dispatch.log_rescued_responses" ] = false
155+ get article_url ( :show )
156+ rescue ActiveRecord ::RecordNotFound => e
157+ # expected
158+ ensure
159+ Rails . application . env_config [ "action_dispatch.show_exceptions" ] = old_show
160+ Rails . application . env_config [ "action_dispatch.log_rescued_responses" ] = old_log_rescued_responses
161+ end
162+ end
163+ assert_equal 3 , messages . count , messages
164+ end
144165 end
145166 end
146167end
You can’t perform that action at this time.
0 commit comments