Use retry_with_error in UserRefreshCredentials#revoke!
This commit is contained in:
parent
a1a9387c2b
commit
40f4e166a2
|
@ -92,15 +92,18 @@ module Google
|
||||||
# Revokes the credential
|
# Revokes the credential
|
||||||
def revoke!(options = {})
|
def revoke!(options = {})
|
||||||
c = options[:connection] || Faraday.default_connection
|
c = options[:connection] || Faraday.default_connection
|
||||||
resp = c.get(REVOKE_TOKEN_URI, token: refresh_token || access_token)
|
|
||||||
case resp.status
|
retry_with_error do
|
||||||
when 200
|
resp = c.get(REVOKE_TOKEN_URI, token: refresh_token || access_token)
|
||||||
self.access_token = nil
|
case resp.status
|
||||||
self.refresh_token = nil
|
when 200
|
||||||
self.expires_at = 0
|
self.access_token = nil
|
||||||
else
|
self.refresh_token = nil
|
||||||
raise(Signet::AuthorizationError,
|
self.expires_at = 0
|
||||||
"Unexpected error code #{resp.status}")
|
else
|
||||||
|
raise(Signet::AuthorizationError,
|
||||||
|
"Unexpected error code #{resp.status}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -293,4 +293,20 @@ describe Google::Auth::UserRefreshCredentials do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'when erros occured with request' do
|
||||||
|
it 'should fail with Signet::AuthorizationError if request times out' do
|
||||||
|
allow_any_instance_of(Faraday::Connection).to receive(:get)
|
||||||
|
.and_raise(Faraday::TimeoutError)
|
||||||
|
expect { @client.revoke! }
|
||||||
|
.to raise_error Signet::AuthorizationError
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail with Signet::AuthorizationError if request fails' do
|
||||||
|
allow_any_instance_of(Faraday::Connection).to receive(:get)
|
||||||
|
.and_raise(Faraday::ConnectionFailed, nil)
|
||||||
|
expect { @client.revoke! }
|
||||||
|
.to raise_error Signet::AuthorizationError
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue