Skip to content

Commit

Permalink
Merge pull request #54 from jeremyf/adding-connection-information-to-…
Browse files Browse the repository at this point in the history
…error-handling

Adding request context to exception message
  • Loading branch information
mwmitchell committed Feb 3, 2013
2 parents 6b56c4a + ab3b1f9 commit 4d10634
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rsolr/connection.rb
Expand Up @@ -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" ?
Expand Down
21 changes: 21 additions & 0 deletions spec/api/connection_spec.rb
Expand Up @@ -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 }
Expand Down

0 comments on commit 4d10634

Please sign in to comment.