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

Added Rate Limit error #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion lib/faraday/raise_http_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def call(env)
when 401 ; raise Postmates::Unauthorized, msg
when 403 ; raise Postmates::Forbidden, msg
when 404 ; raise Postmates::NotFound, msg
when 429 ; raise Postmates::RateLimit, msg
when 500 ; raise Postmates::InternalServerError, msg
when 503 ; raise Postmates::ServiceUnavailable, msg
end
Expand All @@ -25,4 +26,4 @@ def initialize(app)
@parser = nil
end
end
end
end
3 changes: 2 additions & 1 deletion lib/postmates/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class BadRequest < Error; end # 400
class Unauthorized < Error; end # 401
class Forbidden < Error; end # 403
class NotFound < Error; end # 404
class RateLimit < Error; end # 429
class InternalServerError < Error; end # 500
class ServiceUnavailable < Error; end # 503
end
end
19 changes: 18 additions & 1 deletion spec/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@
end
end

describe 'rate limit reached' do
before do
50.times do
stub_post(path_to('deliveries'),
params.merge(response_code: 400,
returns: 'invalid_params.json'))
end
stub_get(path_to('deliveries'),
response_code: 429, returns: 'rate_limit.json')
end

it 'raises Postmates::RateLimit' do
expect { client.list ) }
.to raise_error Postmates::RateLimit
end
end

describe 'when there is a problem processing the request' do
before do
stub_get(path_to('deliveries'),
Expand All @@ -79,4 +96,4 @@
end
end
end
end
end
5 changes: 5 additions & 0 deletions spec/fixtures/rate_limit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"kind": "error",
"code": "rate_limit_exceeded",
"message": "You are attempting to exceed our rate limit"
}