diff --git a/google-apis-core/lib/google/apis/core/api_command.rb b/google-apis-core/lib/google/apis/core/api_command.rb index 22b9b2df8fa..5cb8eb8c0a2 100644 --- a/google-apis-core/lib/google/apis/core/api_command.rb +++ b/google-apis-core/lib/google/apis/core/api_command.rb @@ -30,6 +30,7 @@ class ApiCommand < HttpCommand ERROR_REASON_MAPPING = { 'rateLimitExceeded' => Google::Apis::RateLimitError, 'userRateLimitExceeded' => Google::Apis::RateLimitError, + 'sharingRateLimitExceeded' => Google::Apis::RateLimitError, 'projectNotLinked' => Google::Apis::ProjectNotLinkedError } diff --git a/google-apis-core/spec/google/apis/core/api_command_spec.rb b/google-apis-core/spec/google/apis/core/api_command_spec.rb index eeaf3e23803..826e5a76317 100644 --- a/google-apis-core/spec/google/apis/core/api_command_spec.rb +++ b/google-apis-core/spec/google/apis/core/api_command_spec.rb @@ -330,6 +330,36 @@ end end + context('with a mapped error reason (sharingRateLimitExceeded)') do + let(:command) do + Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals') + end + + before(:example) do + json = <<~JSON + { + "error": { + "errors": [ + { + "domain": "global", + "reason": "sharingRateLimitExceeded", + "message": "Sharing rate limit exceeded" + } + ], + "code": 403, + "message": "Sharing rate limit exceeded" + } + } + JSON + stub_request(:get, 'https://www.googleapis.com/zoo/animals') + .to_return(status: [403, 'Forbidden'], headers: { 'Content-Type' => 'application/json' }, body: json) + end + + it 'should raise a RateLimitError' do + expect { command.execute(client) }.to raise_error(Google::Apis::RateLimitError) + end + end + context('with an empty error body') do let(:command) do Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')