Skip to content

Commit

Permalink
Merge pull request #51 from contentful/add/429-error-handling
Browse files Browse the repository at this point in the history
Add RateLimitExceeded(429) error response
  • Loading branch information
pxlpnk committed Jan 28, 2015
2 parents 9503e3c + 6453ec7 commit 7ec8760
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
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.

0 comments on commit 7ec8760

Please sign in to comment.