Skip to content
Closed
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
9 changes: 8 additions & 1 deletion lib/bootic_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ def delete(href, _ = {}, headers = {})

protected

DEFAULT_TIMEOUT = 10 # seconds

def conn(&block)
@conn ||= Faraday.new do |f|
request_opts = {
timeout: options[:timeout] || DEFAULT_TIMEOUT, # both read/open timeout
open_timeout: options[:open_timeout] || DEFAULT_TIMEOUT, # only open timeout
}

@conn ||= Faraday.new(request: request_opts) do |f|
cache_options = {shared_cache: false, store: options[:cache_store]}
cache_options[:logger] = options[:logger] if options[:logging]

Expand Down
4 changes: 2 additions & 2 deletions lib/bootic_client/strategies/oauth2_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def request_headers

def retryable(&block)
begin
yield
super
rescue AuthorizationError => e
update_token!
yield
super
end
end

Expand Down
14 changes: 13 additions & 1 deletion lib/bootic_client/strategies/strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def inspect

attr_reader :config, :on_new_token

MAX_RETRIES = 3

def validate!
# Overwrite in sub classes
# to raise ArgumentErrors on
Expand All @@ -62,7 +64,17 @@ def pre_flight
# end
#
def retryable(&block)
yield
begin
retries ||= 0
yield
rescue Faraday::ConnectionFailed => e
if (retries += 1) < MAX_RETRIES
# puts "Retrying request, attempt #{retries}"
retry
else
raise
end
end
end

# Noop. Merge these headers into every request.
Expand Down