Commit aff442aa authored by Bryan McLellan's avatar Bryan McLellan
Browse files

Expose http error code on reporting exception

When the server returns an exception we need to at least know what the error
code was to assist in debugging.
parent 70e0f24b
......@@ -118,13 +118,13 @@ class Chef
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
if !e.response || e.response.code.to_s != "404"
if Chef::Config[:enable_reporting_url_fatals]
Chef::Log.error("Received exception attempting to generate run history id (URL Path: #{resource_history_url}), and enable_reporting_url_fatals is set, aborting run.")
Chef::Log.error("Received exception #{"(" + e.response.code + ") " if e.response.code}attempting to generate run history id (URL Path: #{resource_history_url}), and enable_reporting_url_fatals is set, aborting run.")
raise
else
Chef::Log.info("Received exception attempting to generate run history id (URL Path: #{resource_history_url}), disabling reporting for this run.")
Chef::Log.info("Received exception #{"(" + e.response.code + ") " if e.response.code}attempting to generate run history id (URL Path: #{resource_history_url}), disabling reporting for this run.")
end
else
Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported.")
Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported on server.")
end
@reporting_enabled = false
end
......
......@@ -441,18 +441,23 @@ describe Chef::ResourceReporter do
@rest_client.should_receive(:post_rest).
with("reports/nodes/spitfire/runs", {:action => :begin}).
and_raise(@error)
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
end
it "assumes the feature is not enabled" do
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
@resource_reporter.reporting_enabled?.should be_false
end
it "does not send a resource report to the server" do
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
@rest_client.should_not_receive(:post_rest)
@resource_reporter.run_completed(@node)
end
it "prints an error about the error" do
Chef::Log.should_receive(:info).with(/500/)
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
end
end
context "when the server returns a 500 to the client and enable_reporting_url_fatals is true" do
......@@ -471,12 +476,12 @@ describe Chef::ResourceReporter do
Chef::Config[:enable_reporting_url_fatals] = @enable_reporting_url_fatals
end
it "fails the run" do
it "fails the run and prints an message about the error" do
Chef::Log.should_receive(:error).with(/500/)
lambda {
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
}.should raise_error(Net::HTTPServerException)
end
end
context "after creating the run history document" do
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment