Skip to content

Commit

Permalink
Merge pull request #436 from janko-m/raise-connection-error-on-socket…
Browse files Browse the repository at this point in the history
…-writing-exceptions

Raise ConnectionError when writing to socket fails
  • Loading branch information
ixti committed Oct 16, 2017
2 parents fab4fd1 + ea8117e commit f762180
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/http/request/writer.rb
Expand Up @@ -100,6 +100,8 @@ def write(data)
break unless data.bytesize > length
data = data.byteslice(length..-1)
end
rescue IOError, SocketError, SystemCallError => ex
raise ConnectionError, "error writing to socket: #{ex}", ex.backtrace
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/http/request/writer_spec.rb
Expand Up @@ -74,5 +74,15 @@
].join
end
end

context "when writing to socket raises an exception" do
before do
expect(io).to receive(:write).and_raise(Errno::EPIPE)
end

it "raises a ConnectionError" do
expect { writer.stream }.to raise_error(HTTP::ConnectionError)
end
end
end
end

0 comments on commit f762180

Please sign in to comment.