mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
faraday: remove needless override, centralize exception handling more
This commit is contained in:
parent
c2223c93dc
commit
fc440a2486
@ -7,9 +7,14 @@ require "faraday"
|
||||
module Faraday
|
||||
class Adapter
|
||||
class HTTPX < Faraday::Adapter
|
||||
def initialize(app = nil, opts = {}, &block)
|
||||
@connection = @bind = nil
|
||||
super(app, opts, &block)
|
||||
end
|
||||
|
||||
module RequestMixin
|
||||
def build_connection(env)
|
||||
return @connection if defined?(@connection)
|
||||
return @connection if @connection
|
||||
|
||||
@connection = ::HTTPX.plugin(:persistent).plugin(ReasonPlugin)
|
||||
@connection = @connection.with(@connection_options) unless @connection_options.empty?
|
||||
@ -54,6 +59,8 @@ module Faraday
|
||||
Errno::EPIPE,
|
||||
::HTTPX::ConnectionError => e
|
||||
raise Faraday::ConnectionFailed, e
|
||||
rescue ::HTTPX::TimeoutError => e
|
||||
raise Faraday::TimeoutError, e
|
||||
end
|
||||
|
||||
def build_request(env)
|
||||
@ -218,10 +225,10 @@ module Faraday
|
||||
handler.on_complete.call(handler.env) if handler.on_complete
|
||||
end
|
||||
end
|
||||
rescue ::HTTPX::TimeoutError => e
|
||||
raise Faraday::TimeoutError, e
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# from Faraday::Adapter#connection
|
||||
def connection(env)
|
||||
conn = build_connection(env)
|
||||
@ -230,8 +237,6 @@ module Faraday
|
||||
yield conn
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# from Faraday::Adapter#request_timeout
|
||||
def request_timeout(type, options)
|
||||
key = Faraday::Adapter::TIMEOUT_KEYS[type]
|
||||
@ -284,8 +289,6 @@ module Faraday
|
||||
response.raise_for_status unless response.is_a?(::HTTPX::Response)
|
||||
response
|
||||
end
|
||||
rescue ::HTTPX::TimeoutError => e
|
||||
raise Faraday::TimeoutError, e
|
||||
end
|
||||
|
||||
def parallel?(env)
|
||||
|
Loading…
x
Reference in New Issue
Block a user