summaryrefslogtreecommitdiff
path: root/lib/chef/resource_reporter.rb
diff options
context:
space:
mode:
authorHugo Lopes Tavares <hltbra@gmail.com>2014-07-08 12:13:26 -0400
committerHugo Lopes Tavares <hltbra@gmail.com>2014-07-08 12:13:26 -0400
commitee81c7e400b8ede275c4e91afda19caf099c06d4 (patch)
tree82d8f9fc374d1bb3d766c6a1fa9f99d9a93b41b5 /lib/chef/resource_reporter.rb
parenta29da10fdfde1f3aacf3ec2b0f2b23c1193a185b (diff)
downloadchef-ee81c7e400b8ede275c4e91afda19caf099c06d4.tar.gz
Tweak ResourceReporter#post_reporting_data for better logs and safer exception handling
Diffstat (limited to 'lib/chef/resource_reporter.rb')
-rw-r--r--lib/chef/resource_reporter.rb13
1 files changed, 6 insertions, 7 deletions
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