Skip to content

Commit f671218

Browse files
committed
Do not attempt to convert ActionDispatch::Reqest/Response to JSON
1 parent 4204111 commit f671218

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

meta_request/lib/meta_request/event.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def json_encodable(payload)
4040
transform_hash(payload, deep: true) do |hash, key, value|
4141
if value.class.to_s == 'ActionDispatch::Http::Headers'
4242
value = value.to_h.select { |k, _| k.upcase == k }
43-
elsif defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
43+
elsif not_encodable?(value)
4444
value = NOT_JSON_ENCODABLE
4545
end
4646

@@ -54,6 +54,11 @@ def json_encodable(payload)
5454
end.with_indifferent_access
5555
end
5656

57+
def not_encodable?(value)
58+
(defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)) ||
59+
(defined?(ActionDispatch) && (value.is_a?(ActionDispatch::Request)) || value.is_a?(ActionDispatch::Response))
60+
end
61+
5762
# https://gist.github.com/dbenhur/1070399
5863
def transform_hash(original, options = {}, &block)
5964
options[:safe_descent] ||= {}

0 commit comments

Comments
 (0)