Skip to content
Browse files

Adding request context to exception message

Prior to this patch, I would receive the following exception:
```
Errno::ECONNREFUSED (Connection refused - connect(2))
```

With this patch, I receive the equivalent of:
```
Errno::ECONNREFUSED: Connection refused - {
  :uri=>#<URI::HTTP:0x007fd5093b22a8 URL:http://localhost/some_uri>,
  :method=>:get,
  :open_timeout=>42
}
``
  • Loading branch information...
1 parent 6b56c4a commit ab3b1f9342502154c9ca5b24187918b6658e6f34 @jeremyf jeremyf committed
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 ab3b1f9

Please sign in to comment.
Something went wrong with that request. Please try again.