Skip to content

Commit

Permalink
Add RateLimitExceeded(429) error response
Browse files Browse the repository at this point in the history
  • Loading branch information
pxlpnk committed Jan 28, 2015
1 parent 9503e3c commit 948aa51
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/contentful/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def self.[](error_status_code)
AccessDenied
when 401
Unauthorized
when 429
RateLimitExceeded
when 500
ServerError
when 503
Expand All @@ -43,6 +45,9 @@ class AccessDenied < Error; end
# 401
class Unauthorized < Error; end

# 429
class RateLimitExceeded < Error; end

# 500
class ServerError < Error; end

Expand Down
11 changes: 9 additions & 2 deletions spec/error_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@
client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')

expect_vcr('unauthorized'){
client.entry 'nyancat'
client.entry('nyancat')
}.to raise_error(Contentful::Unauthorized)
end

it 'will return 500 (ServerError) if ...' do
skip
end

it 'will return a 429 if the ratelimit is hit' do
client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')
expect_vcr('ratelimit') {
client.entry('nyancat')
}.to raise_error(Contentful::RateLimitExceeded)
end

it 'will return 503 (ServiceUnavailable) if connection time out' do
client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')

expect_vcr('unavailable'){
client.entry 'nyancat'
client.entry('nyancat')
}.to raise_error(Contentful::ServiceUnavailable)
end
end
64 changes: 64 additions & 0 deletions spec/fixtures/vcr_cassettes/ratelimit.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 948aa51

Please sign in to comment.