Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
veryfi (4.0.0)
veryfi (4.0.1)
base64 (~> 0.1)
faraday (>= 2.14.1, < 3.0)
openssl (>= 2.2, < 4.1)
Expand All @@ -23,15 +23,15 @@ GEM
rexml
diff-lcs (1.6.2)
docile (1.4.1)
faraday (2.14.2)
faraday (2.14.3)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.3)
faraday-net_http (3.4.4)
net-http (~> 0.5)
hashdiff (1.2.1)
io-console (0.8.2)
json (2.19.5)
json (2.20.0)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/veryfi/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def initialize(
api_key:,
base_url: "https://api.veryfi.com/api/",
api_version: "v8",
timeout: 20,
timeout: 30,
faraday: nil
)
@request = Veryfi::Request.new(
Expand Down
2 changes: 1 addition & 1 deletion lib/veryfi/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Configuration
def initialize
@base_url = "https://api.veryfi.com/api/"
@api_version = "v8"
@timeout = 20
@timeout = 30
end

# @return [Hash] the configuration as a keyword-arg-ready Hash. Keys
Expand Down
12 changes: 10 additions & 2 deletions lib/veryfi/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def make_request(http_verb, path, params = {})
url = [api_url, path].join
body = generate_body(http_verb, params)
headers = generate_headers(params)

response = conn.public_send(http_verb, url, body, headers)
response = attempt_request(http_verb, url, body, headers)
json_response = process_response(response)

if response.success?
Expand All @@ -75,6 +74,15 @@ def make_request(http_verb, path, params = {})
end
end

def attempt_request(http_verb, url, body, headers)
conn.public_send(http_verb, url, body, headers)
rescue Faraday::TimeoutError => e
raise unless e.message.include?("closed")

@_conn = nil
conn.public_send(http_verb, url, body, headers)
end

def conn
@_conn ||= Faraday.new do |conn|
conn.options.timeout = timeout
Expand Down
2 changes: 1 addition & 1 deletion lib/veryfi/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Veryfi
VERSION = "4.0.0"
VERSION = "4.0.1"
end
23 changes: 23 additions & 0 deletions spec/veryfi/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@
end
end

describe "stale connection recovery" do
let(:request) do
described_class.new("cid", nil, "u", "k", "https://api.veryfi.com/api/", "v8", 30)
end

let(:endpoint) { "https://api.veryfi.com/api/v8/partner/documents/" }

it "retries once after a closed-socket ReadTimeout" do
stub_request(:get, endpoint)
.to_raise(Faraday::TimeoutError.new("Net::ReadTimeout with #<TCPSocket:(closed)>")).then
.to_return(status: 200, body: '[{"id":1}]')

expect { request.get("/partner/documents/") }.not_to raise_error
end

it "re-raises Faraday::TimeoutError when the socket is not closed" do
stub_request(:get, endpoint)
.to_raise(Faraday::TimeoutError.new("execution expired"))

expect { request.get("/partner/documents/") }.to raise_error(Faraday::TimeoutError, /execution expired/)
end
end

context "when server responds with empty body" do
before do
stub_request(:get, /\.*/).to_return(status: 501, body: "")
Expand Down
2 changes: 1 addition & 1 deletion spec/veryfi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
it "exposes sensible defaults" do
expect(described_class.configuration.base_url).to eq("https://api.veryfi.com/api/")
expect(described_class.configuration.api_version).to eq("v8")
expect(described_class.configuration.timeout).to eq(20)
expect(described_class.configuration.timeout).to eq(30)
end
end

Expand Down
Loading