aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-01-02 14:16:15 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-01-02 14:16:15 -0300
commit2d743b528cf8ee2a8dc016a5dd0d54bf7cbc34e4 (patch)
tree52add4e98ac9bd49f6e11013faf3ad0c1d6e9961
parent873870df4cbb0b79d1cb6d811cf68d3aa9fdc625 (diff)
parent2fde159f6b22fa45f132ba25c48eb3c371ead949 (diff)
downloadrails-2d743b528cf8ee2a8dc016a5dd0d54bf7cbc34e4.tar.gz
rails-2d743b528cf8ee2a8dc016a5dd0d54bf7cbc34e4.tar.bz2
rails-2d743b528cf8ee2a8dc016a5dd0d54bf7cbc34e4.zip
Merge pull request #17978 from kommen/fixed-pr-14903
Ensure append_info_to_payload is called even if an exception is raised. Conflicts: actionpack/CHANGELOG.md
-rw-r--r--actionpack/CHANGELOG.md11
-rw-r--r--actionpack/lib/action_controller/metal/instrumentation.rb11
-rw-r--r--actionpack/test/controller/log_subscriber_test.rb20
3 files changed, 38 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 3f29d810d5..838380ff71 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,14 @@
+* Ensure `append_info_to_payload` is called even if an exception is raised.
+
+ Fixes an issue where when an exception is raised in the request the additonal
+ payload data is not available.
+
+ See:
+ * #14903
+ * https://github.com/roidrage/lograge/issues/37
+
+ *Dieter Komendera*, *Margus Pärt*
+
* Correctly rely on the response's status code to handle calls to `head`.
*Robin Dupret*
diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb
index bef7545e71..a3e1a71b0a 100644
--- a/actionpack/lib/action_controller/metal/instrumentation.rb
+++ b/actionpack/lib/action_controller/metal/instrumentation.rb
@@ -28,10 +28,13 @@ module ActionController
ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup)
ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload|
- result = super
- payload[:status] = response.status
- append_info_to_payload(payload)
- result
+ begin
+ result = super
+ payload[:status] = response.status
+ result
+ ensure
+ append_info_to_payload(payload)
+ end
end
end
diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb
index 49be7caf38..864c6ee130 100644
--- a/actionpack/test/controller/log_subscriber_test.rb
+++ b/actionpack/test/controller/log_subscriber_test.rb
@@ -73,6 +73,16 @@ module Another
def with_action_not_found
raise AbstractController::ActionNotFound
end
+
+ def append_info_to_payload(payload)
+ super
+ payload[:test_key] = "test_value"
+ @last_payload = payload
+ end
+
+ def last_payload
+ @last_payload
+ end
end
end
@@ -163,6 +173,16 @@ class ACLogSubscriberTest < ActionController::TestCase
assert_match(/\(Views: [\d.]+ms\)/, logs[1])
end
+ def test_append_info_to_payload_is_called_even_with_exception
+ begin
+ get :with_exception
+ wait
+ rescue Exception
+ end
+
+ assert_equal "test_value", @controller.last_payload[:test_key]
+ end
+
def test_process_action_with_filter_parameters
@request.env["action_dispatch.parameter_filter"] = [:lifo, :amount]