Skip to content

Commit

Permalink
Implement retry_with_faraday_error
Browse files Browse the repository at this point in the history
  • Loading branch information
serihiro committed Feb 26, 2017
1 parent 37ed189 commit 960cac2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/googleauth/signet.rb
Expand Up @@ -77,6 +77,25 @@ def notify_refresh_listeners
block.call(self)
end
end

def retry_with_error(max_retry_count = 5)
retry_count = 0

begin
yield
rescue => e
raise e if e.is_a?(Signet::AuthorizationError) || e.is_a?(Signet::ParseError)

if retry_count < max_retry_count
retry_count += 1
sleep retry_count * 0.3
retry
else
msg = "Unexpected error: #{e.inspect}"
raise(Signet::AuthorizationError, msg)
end
end
end
end
end
end

0 comments on commit 960cac2

Please sign in to comment.