Skip to content

Commit

Permalink
Have IO exceptions reraise HTTP::ConnectionError (closes #303)
Browse files Browse the repository at this point in the history
These make it easier to handle HTTP errors generically
  • Loading branch information
tarcieri committed Apr 3, 2016
1 parent 96d276f commit 7e89584
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/http/connection.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -94,16 +94,14 @@ 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
end
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
Expand Down Expand Up @@ -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

0 comments on commit 7e89584

Please sign in to comment.