diff --git a/CHANGELOG.md b/CHANGELOG.md index bb8f2ef..c619940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.8.1 + +- Makes the retryable_request method also retry when a `RDStation::Error::Unauthorized` error happen + ## 2.8.0 ### Additions diff --git a/lib/rdstation/retryable_request.rb b/lib/rdstation/retryable_request.rb index 650fbf1..2478fa3 100644 --- a/lib/rdstation/retryable_request.rb +++ b/lib/rdstation/retryable_request.rb @@ -7,7 +7,7 @@ def retryable_request(authorization) retries = 0 begin yield authorization - rescue ::RDStation::Error::ExpiredAccessToken => e + rescue ::RDStation::Error::ExpiredAccessToken, ::RDStation::Error::Unauthorized => e raise if !retry_possible?(authorization) || retries >= MAX_RETRIES retries += 1 diff --git a/lib/rdstation/version.rb b/lib/rdstation/version.rb index c8369d9..113fa72 100644 --- a/lib/rdstation/version.rb +++ b/lib/rdstation/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RDStation - VERSION = '2.8.0' + VERSION = '2.8.1' end diff --git a/spec/lib/rdstation/retryable_request_spec.rb b/spec/lib/rdstation/retryable_request_spec.rb index 73a8c59..d89573c 100644 --- a/spec/lib/rdstation/retryable_request_spec.rb +++ b/spec/lib/rdstation/retryable_request_spec.rb @@ -56,7 +56,7 @@ class DummyClass and_return(new_credentials) end - it 'refreshes the access_token and retries the request' do + it 'refreshes the access_token and retries the request when an ExpiredAccessToken error happen' do dummy_request = double("dummy_request") expect(dummy_request).to receive(:call).twice do |auth| expired_token = ::RDStation::Error::ExpiredAccessToken.new({'error_message' => 'x'}) @@ -74,6 +74,24 @@ class DummyClass end.not_to raise_error end + it 'refreshes the access_token and retries the request an Unauthorized error happen' do + dummy_request = double("dummy_request") + expect(dummy_request).to receive(:call).twice do |auth| + expired_token = ::RDStation::Error::Unauthorized.new({'error_message' => 'x'}) + raise expired_token unless auth.access_token == new_access_token + end + + expect(RDStation.configuration.access_token_refresh_callback) + .to receive(:call) + .once do |authorization| + expect(authorization.access_token).to eq new_access_token + end + + expect do + subject.retryable_request(auth) { |yielded_auth| dummy_request.call(yielded_auth) } + end.not_to raise_error + end + context 'and keeps raising retryable exception event after token refreshed' do it 'retries only once' do dummy_request = double("dummy_request")