Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix nested hash problem when using remote_url storage strategy

  • Loading branch information...
commit 97df13b76c2074300bc3b76356605063b150bf32 1 parent ee09a69
@Sharagoz Sharagoz authored
View
30 lib/rails_exception_handler/storage.rb
@@ -13,7 +13,35 @@ def self.rails_log(info)
def self.remote_url(target, info)
uri = URI.parse(target)
- params = {:error_message => info}
+ params = flatten_hash({:error_message => info})
Net::HTTP::post_form(uri, params)
end
+
+ private
+
+ # Credit: Hash flattening technique borrowed from Peter Marklund: http://marklunds.com/articles/one/314
+ def self.flatten_hash(hash, ancestor_names = [])
+ flat_hash = {}
+ hash.each do |k, v|
+ names = Array.new(ancestor_names)
+ names << k
+ if v.is_a?(Hash)
+ flat_hash.merge!(flatten_hash(v, names))
+ else
+ key = flat_hash_key(names)
+ key += "[]" if v.is_a?(Array)
+ flat_hash[key] = v
+ end
+ end
+ flat_hash
+ end
+
+ def self.flat_hash_key(names)
+ names = Array.new(names)
+ name = names.shift.to_s.dup
+ names.each do |n|
+ name << "[#{n}]"
+ end
+ name
+ end
end
View
2  spec/integration/storage_spec.rb
@@ -65,7 +65,7 @@
parser = @handler.instance_variable_get(:@parsed_error)
RailsExceptionHandler.configure { |config| config.storage_strategies = [:remote_url => {:target => 'http://example.com/error_messages'}] }
uri = URI.parse('http://example.com/error_messages')
- params = { :error_message => parser.external_info }
+ params = RailsExceptionHandler::Storage.send(:flatten_hash, { :error_message => parser.external_info })
Net::HTTP.should_receive(:post_form).with(uri, params)
@handler.handle_exception
end
Please sign in to comment.
Something went wrong with that request. Please try again.