Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions google-apis-core/lib/google/apis/core/api_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
30 changes: 30 additions & 0 deletions google-apis-core/spec/google/apis/core/api_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading