#445 - Treat 429 status codes as rate limit errors
This commit is contained in:
parent
2046e00f14
commit
2578736b44
|
@ -203,6 +203,9 @@ module Google
|
|||
when 401
|
||||
message ||= 'Unauthorized'
|
||||
raise Google::Apis::AuthorizationError.new(message, status_code: status, header: header, body: body)
|
||||
when 429
|
||||
message ||= 'Rate limit exceeded'
|
||||
raise Google::Apis::RateLimitError.new(message, status_code: status, header: header, body: body)
|
||||
when 304, 400, 402...500
|
||||
message ||= 'Invalid request'
|
||||
raise Google::Apis::ClientError.new(message, status_code: status, header: header, body: body)
|
||||
|
|
|
@ -299,4 +299,11 @@ RSpec.describe Google::Apis::Core::HttpCommand do
|
|||
command.options.retries = 0
|
||||
expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError)
|
||||
end
|
||||
|
||||
it 'should raise rate limit error for 429 status codes' do
|
||||
stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_return(status: [429, ''])
|
||||
command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
||||
command.options.retries = 0
|
||||
expect { command.execute(client) }.to raise_error(Google::Apis::RateLimitError)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue