diff --git a/lib/googleauth/user_refresh.rb b/lib/googleauth/user_refresh.rb index 14c1990..65d310f 100644 --- a/lib/googleauth/user_refresh.rb +++ b/lib/googleauth/user_refresh.rb @@ -92,15 +92,18 @@ module Google # Revokes the credential def revoke!(options = {}) c = options[:connection] || Faraday.default_connection - resp = c.get(REVOKE_TOKEN_URI, token: refresh_token || access_token) - case resp.status - when 200 - self.access_token = nil - self.refresh_token = nil - self.expires_at = 0 - else - raise(Signet::AuthorizationError, - "Unexpected error code #{resp.status}") + + retry_with_error do + resp = c.get(REVOKE_TOKEN_URI, token: refresh_token || access_token) + case resp.status + when 200 + self.access_token = nil + self.refresh_token = nil + self.expires_at = 0 + else + raise(Signet::AuthorizationError, + "Unexpected error code #{resp.status}") + end end end diff --git a/spec/googleauth/user_refresh_spec.rb b/spec/googleauth/user_refresh_spec.rb index d80f6ba..cc81476 100644 --- a/spec/googleauth/user_refresh_spec.rb +++ b/spec/googleauth/user_refresh_spec.rb @@ -293,4 +293,20 @@ describe Google::Auth::UserRefreshCredentials do ) 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