From 7e895847dba6b6e0c26e206d352f0e3a80b0bd57 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sun, 3 Apr 2016 13:10:41 -0700 Subject: [PATCH] Have IO exceptions reraise HTTP::ConnectionError (closes #303) These make it easier to handle HTTP errors generically --- lib/http/connection.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/http/connection.rb b/lib/http/connection.rb index 79d5e0a0..81bc49e2 100644 --- a/lib/http/connection.rb +++ b/lib/http/connection.rb @@ -37,8 +37,8 @@ def initialize(req, options) send_proxy_connect_request(req) start_tls(req, options) reset_timer - rescue SocketError, SystemCallError => e - raise ConnectionError, "failed to connect: #{e}" + rescue IOError, SocketError, SystemCallError => ex + raise ConnectionError, "failed to connect: #{ex}", ex.backtrace end # @see (HTTP::Response::Parser#status_code) @@ -94,7 +94,7 @@ def readpartial(size = BUFFER_SIZE) def read_headers! loop do if read_more(BUFFER_SIZE) == :eof - fail EOFError unless @parser.headers? + fail ConnectionError, "couldn't read response headers" unless @parser.headers? break elsif @parser.headers? break @@ -102,8 +102,6 @@ def read_headers! end set_keep_alive - rescue IOError, Errno::ECONNRESET, Errno::EPIPE => e - raise ConnectionError, "failed to read headers: #{e}" end # Callback for when we've reached the end of a response @@ -213,6 +211,8 @@ def read_more(size) elsif value @parser << value end + rescue IOError, SocketError, SystemCallError => ex + raise ConnectionError, "error reading from socket: #{ex}", ex.backtrace end end end