Implement retry_with_faraday_error

This commit is contained in:
Kazuhiro Serizawa 2016-12-08 00:56:14 +09:00
parent 0f7fe1ea91
commit 3014e6ddaf
1 changed files with 19 additions and 0 deletions

View File

@ -77,6 +77,25 @@ module Signet
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