Skip to content

Commit d327ccb

Browse files
rgisigerrgisiger
authored andcommitted
Add connection error handling method to reduce ABC-Metric of the request method
1 parent 4b3345e commit d327ccb

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

rb/lib/selenium/webdriver/remote/http/default.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ def request(verb, url, headers, payload, redirects = 0)
8888
sleep 2
8989
retry
9090
rescue Errno::ECONNREFUSED => e
91-
raise e.class, "using proxy: #{http.proxy_uri}" if http.proxy?
92-
93-
raise
91+
handle_connection_refused(e)
9492
end
9593

9694
if response.is_a? Net::HTTPRedirection
@@ -104,6 +102,12 @@ def request(verb, url, headers, payload, redirects = 0)
104102
end
105103
end
106104

105+
def handle_connection_refused(error)
106+
raise error.class, "using proxy: #{http.proxy_uri}" if http.proxy?
107+
108+
raise
109+
end
110+
107111
def new_request_for(verb, url, headers, payload)
108112
req = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)
109113

rb/sig/lib/selenium/webdriver/remote/http/default.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ module Selenium
3232

3333
def request: (untyped verb, untyped url, untyped headers, untyped payload, ?::Integer redirects) -> untyped
3434

35+
def handle_connection_refused: (Errno::ECONNREFUSED exception) -> untyped
36+
3537
def new_request_for: (untyped verb, untyped url, untyped headers, untyped payload) -> untyped
3638

3739
def response_for: (untyped request) -> untyped

0 commit comments

Comments
 (0)