Browse files

Merge pull request #54 from jeremyf/adding-connection-information-to-…

…error-handling

Adding request context to exception message
  • Loading branch information...
2 parents 6b56c4a + ab3b1f9 commit 4d1063449fd5282da7e76de875cb80cee8606961 @mwmitchell mwmitchell committed Feb 3, 2013
Showing with 23 additions and 0 deletions.
  1. +2 −0 lib/rsolr/connection.rb
  2. +21 −0 spec/api/connection_spec.rb
View
2 lib/rsolr/connection.rb
@@ -15,6 +15,8 @@ def execute client, request_context
response = h.request request
charset = response.type_params["charset"]
{:status => response.code.to_i, :headers => response.to_hash, :body => force_charset(response.body, charset)}
+ rescue Errno::ECONNREFUSED => e
+ raise(Errno::ECONNREFUSED.new(request_context.inspect))
# catch the undefined closed? exception -- this is a confirmed ruby bug
rescue NoMethodError
$!.message == "undefined method `closed?' for nil:NilClass" ?
View
21 spec/api/connection_spec.rb
@@ -57,6 +57,27 @@
subject.execute client, {:uri => URI.parse("http://localhost/some_uri"), :method => :get}
end
end
+
+ context "connection refused" do
+ let(:client) { mock.as_null_object }
+
+ let(:http) { mock(Net::HTTP).as_null_object }
+ let(:request_context) {
+ {:uri => URI.parse("http://localhost/some_uri"), :method => :get, :open_timeout => 42}
+ }
+ subject { RSolr::Connection.new }
+
+ before do
+ Net::HTTP.stub(:new) { http }
+ end
+
+ it "should configure Net:HTTP open_timeout" do
+ http.should_receive(:request).and_raise(Errno::ECONNREFUSED)
+ lambda {
+ subject.execute client, request_context
+ }.should raise_error(Errno::ECONNREFUSED, /#{request_context}/)
+ end
+ end
describe "basic auth support" do
let(:http) { mock(Net::HTTP).as_null_object }

0 comments on commit 4d10634

Please sign in to comment.