Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RateLimitExceeded(429) error response #51

Merged
merged 2 commits into from
Jan 28, 2015
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Unreleased
### Fixed
* Better handling of 503 responses from the API [#48](https://github.com/contentful/contentful-management.rb/pull/48)
* Better handling of 429 responses from the API [#51](https://github.com/contentful/contentful-management.rb/pull/51)

### Added
* `focus` and `fit` to image handling parameters [#44](https://github.com/contentful/contentful.rb/pull/44)
Expand Down
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.