lib/httpx/channel.rb in httpx-0.0.4 vs lib/httpx/channel.rb in httpx-0.0.5
- old
+ new
@@ -64,10 +64,11 @@
@window_size = @options.window_size
@read_buffer = Buffer.new(BUFFER_SIZE)
@write_buffer = Buffer.new(BUFFER_SIZE)
@pending = []
@state = :idle
+ on(:error) { |ex| on_error(ex) }
end
def match?(uri)
return false if @state == :closing
ips = begin
@@ -202,10 +203,14 @@
transition(:closed)
transition(:idle)
transition(:open)
end
end
+ parser.on(:error) do |request, ex|
+ response = ErrorResponse.new(ex, 0, @options)
+ emit(:response, request, response)
+ end
parser
end
def transition(nextstate)
case nextstate
@@ -228,15 +233,21 @@
rescue Errno::ECONNREFUSED,
Errno::ENETUNREACH,
Errno::EADDRNOTAVAIL,
OpenSSL::SSL::SSLError => e
# connect errors, exit gracefully
- emit_error(e)
+ handle_error(e)
@state = :closed
emit(:close)
end
- def emit_error(e)
+ def on_error(ex)
+ handle_error(ex)
+ reset
+ end
+
+ def handle_error(e)
+ parser.handle_error(e)
response = ErrorResponse.new(e, 0, @options)
@pending.each do |request, _|
emit(:response, request, response)
end
end