From ee81c7e400b8ede275c4e91afda19caf099c06d4 Mon Sep 17 00:00:00 2001 From: Hugo Lopes Tavares Date: Tue, 8 Jul 2014 12:13:26 -0400 Subject: Tweak ResourceReporter#post_reporting_data for better logs and safer exception handling --- lib/chef/resource_reporter.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lib/chef/resource_reporter.rb') diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb index 8f6d66cd5d..046e4e82c6 100644 --- a/lib/chef/resource_reporter.rb +++ b/lib/chef/resource_reporter.rb @@ -231,18 +231,17 @@ class Chef Chef::Log.info("Sending resource update report (run-id: #{run_id})") Chef::Log.debug run_data.inspect compressed_data = encode_gzip(run_data.to_json) + Chef::Log.debug("Sending compressed run data...") + # Since we're posting compressed data we can not directly call post_rest which expects JSON + reporting_url = @rest_client.create_url(resource_history_url) begin - Chef::Log.debug("Sending compressed run data...") - # Since we're posting compressed data we can not directly call post_rest which expects JSON - reporting_url = @rest_client.create_url(resource_history_url) @rest_client.raw_http_request(:POST, reporting_url, headers({'Content-Encoding' => 'gzip'}), compressed_data) rescue StandardError => e - raise if !e.respond_to? :response - if e.response.code.to_s == "400" + if e.respond_to? :response Chef::FileCache.store("failed-reporting-data.json", Chef::JSONCompat.to_json_pretty(run_data), 0640) - Chef::Log.error("Failed to post reporting data to server (HTTP 400), saving to #{Chef::FileCache.load("failed-reporting-data.json", false)}") + Chef::Log.error("Failed to post reporting data to server (HTTP #{e.response.code}), saving to #{Chef::FileCache.load("failed-reporting-data.json", false)}") else - Chef::Log.error("Failed to post reporting data to server (HTTP #{e.response.code.to_s})") + Chef::Log.error("Failed to post reporting data to server (#{e})") end end else -- cgit v1.2.1