Skip to content

Commit 786ef91

Browse files
committed
fix(google-apis-core): map sharingRateLimitExceeded to RateLimitError
fixes: #26531
1 parent 775eac6 commit 786ef91

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

google-apis-core/lib/google/apis/core/api_command.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ApiCommand < HttpCommand
3030
ERROR_REASON_MAPPING = {
3131
'rateLimitExceeded' => Google::Apis::RateLimitError,
3232
'userRateLimitExceeded' => Google::Apis::RateLimitError,
33+
'sharingRateLimitExceeded' => Google::Apis::RateLimitError,
3334
'projectNotLinked' => Google::Apis::ProjectNotLinkedError
3435
}
3536

google-apis-core/spec/google/apis/core/api_command_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,36 @@
330330
end
331331
end
332332

333+
context('with a mapped error reason (sharingRateLimitExceeded)') do
334+
let(:command) do
335+
Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
336+
end
337+
338+
before(:example) do
339+
json = <<~JSON
340+
{
341+
"error": {
342+
"errors": [
343+
{
344+
"domain": "global",
345+
"reason": "sharingRateLimitExceeded",
346+
"message": "Sharing rate limit exceeded"
347+
}
348+
],
349+
"code": 403,
350+
"message": "Sharing rate limit exceeded"
351+
}
352+
}
353+
JSON
354+
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
355+
.to_return(status: [403, 'Forbidden'], headers: { 'Content-Type' => 'application/json' }, body: json)
356+
end
357+
358+
it 'should raise a RateLimitError' do
359+
expect { command.execute(client) }.to raise_error(Google::Apis::RateLimitError)
360+
end
361+
end
362+
333363
context('with an empty error body') do
334364
let(:command) do
335365
Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')

0 commit comments

Comments
 (0)