lib/httpx/adapters/faraday.rb in httpx-0.22.2 vs lib/httpx/adapters/faraday.rb in httpx-0.22.3

- old
+ new

@@ -208,13 +208,17 @@ def call(env) super if parallel?(env) handler = env[:parallel_manager].enqueue(env) handler.on_response do |response| - response.raise_for_status - save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers| - response_headers.merge!(response.headers) + if response.is_a?(::HTTPX::Response) + save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers| + response_headers.merge!(response.headers) + end + else + env[:error] = response.error + save_response(env, 0, "", {}, nil) end end return handler end @@ -227,9 +231,10 @@ request = session.build_request(*build_request(env)) request.response_on_data = env.request.on_data if env.request.stream_response? response = session.request(request) + # do not call #raise_for_status for HTTP 4xx or 5xx, as faraday has a middleware for that. response.raise_for_status unless response.is_a?(::HTTPX::Response) save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers| response_headers.merge!(response.headers) end @app.call(env)