Skip to content

Instantly share code, notes, and snippets.

@thbishop
Created September 11, 2010 23:37
Show Gist options
  • Save thbishop/575683 to your computer and use it in GitHub Desktop.
Save thbishop/575683 to your computer and use it in GitHub Desktop.
begin
res = @http.request(req)
unless res.kind_of?(Net::HTTPSuccess)
res.error!
end
rescue Timeout::Error, Errno::EINVAL, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, NoMethodError => e
# http://redmine.ruby-lang.org/issues/show/2708
# http://redmine.ruby-lang.org/issues/show/2758
if e.to_s =~ /#{Regexp.escape(%q|undefined method 'closed?' for nil:NilClass|)}/
Chef::Log.fatal("POST to Solr encountered exception Errno::ECONNREFUSED: net/http undefined method closed?")
Chef::Log.debug("rescued error in http connect, treating it as Errno::ECONNREFUSED to hide bug in net/http")
raise Errno::ECONNREFUSED
else
Chef::Log.fatal("POST to Solr encountered exception #{e.class}: #{e.to_s}")
end
raise e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment