From c39c6a2775ad3931a9ece2e847eb7d79a37ba048 Mon Sep 17 00:00:00 2001 From: Craig Shannon Date: Mon, 16 Mar 2020 08:21:53 -0700 Subject: [PATCH 1/2] embed response from proxy in ProxyConnectionError --- lib/excon/error.rb | 11 ++++++++++- lib/excon/ssl_socket.rb | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/excon/error.rb b/lib/excon/error.rb index 99374911..619c2520 100644 --- a/lib/excon/error.rb +++ b/lib/excon/error.rb @@ -50,7 +50,16 @@ class InvalidHeaderKey < Error; end class InvalidHeaderValue < Error; end class Timeout < Error; end class ResponseParse < Error; end - class ProxyConnectionError < Error; end + + class ProxyConnectionError < Error + attr_reader :proxy_response + + def initialize(msg, proxy_response = nil) + super(msg) + @proxy_response = proxy_response + end + end + class ProxyParse < Error; end class TooManyRedirects < Error; end diff --git a/lib/excon/ssl_socket.rb b/lib/excon/ssl_socket.rb index 8ec32401..04b8de21 100644 --- a/lib/excon/ssl_socket.rb +++ b/lib/excon/ssl_socket.rb @@ -109,7 +109,7 @@ def initialize(data = {}) # eat the proxy's connection response response = Excon::Response.parse(self, :expects => 200, :method => 'CONNECT') if response[:response][:status] != 200 - raise(Excon::Errors::ProxyConnectionError.new("proxy connection is not exstablished")) + raise(Excon::Errors::ProxyConnectionError.new("proxy connection could not be established", response)) end end From 36744bd2e60a89d2e22f79ac90d9a93544a1e34b Mon Sep 17 00:00:00 2001 From: Craig Shannon Date: Mon, 16 Mar 2020 10:04:58 -0700 Subject: [PATCH 2/2] include both request and response in ProxyConnectionError --- lib/excon/error.rb | 7 ++++--- lib/excon/ssl_socket.rb | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/excon/error.rb b/lib/excon/error.rb index 619c2520..58945a17 100644 --- a/lib/excon/error.rb +++ b/lib/excon/error.rb @@ -52,11 +52,12 @@ class Timeout < Error; end class ResponseParse < Error; end class ProxyConnectionError < Error - attr_reader :proxy_response + attr_reader :request, :response - def initialize(msg, proxy_response = nil) + def initialize(msg, request = nil, response = nil) super(msg) - @proxy_response = proxy_response + @request = request + @response = response end end diff --git a/lib/excon/ssl_socket.rb b/lib/excon/ssl_socket.rb index 04b8de21..f07e6df4 100644 --- a/lib/excon/ssl_socket.rb +++ b/lib/excon/ssl_socket.rb @@ -109,7 +109,7 @@ def initialize(data = {}) # eat the proxy's connection response response = Excon::Response.parse(self, :expects => 200, :method => 'CONNECT') if response[:response][:status] != 200 - raise(Excon::Errors::ProxyConnectionError.new("proxy connection could not be established", response)) + raise(Excon::Errors::ProxyConnectionError.new("proxy connection could not be established", request, response)) end end