diff --git a/lib/createsend/createsend.rb b/lib/createsend/createsend.rb index d0697b6..91ff055 100644 --- a/lib/createsend/createsend.rb +++ b/lib/createsend/createsend.rb @@ -30,6 +30,8 @@ class BadRequest < CreateSendError; end class Unauthorized < CreateSendError; end # Raised for HTTP response code of 404 class NotFound < ClientError; end + # Raised for HTTP response code of 429 + class TooManyRequests < ClientError; end # Raised for HTTP response code of 401, specifically when an OAuth token # in invalid (Code: 120, Message: 'Invalid OAuth Token') @@ -279,6 +281,8 @@ def handle_response(response) # :nodoc: end when 404 raise NotFound.new + when 429 + raise TooManyRequests.new when 400...500 raise ClientError.new when 500...600 diff --git a/test/createsend_test.rb b/test/createsend_test.rb index 538bcb4..4668f4b 100644 --- a/test/createsend_test.rb +++ b/test/createsend_test.rb @@ -278,11 +278,12 @@ class CreateSendTest < Test::Unit::TestCase @template = CreateSend::Template.new @auth, '98y2e98y289dh89h938389' end - { ["400", "Bad Request"] => CreateSend::BadRequest, - ["401", "Unauthorized"] => CreateSend::Unauthorized, - ["404", "Not Found"] => CreateSend::NotFound, - ["418", "I'm a teapot"] => CreateSend::ClientError, - ["500", "Server Error"] => CreateSend::ServerError + { ["400", "Bad Request"] => CreateSend::BadRequest, + ["401", "Unauthorized"] => CreateSend::Unauthorized, + ["404", "Not Found"] => CreateSend::NotFound, + ["418", "I'm a teapot"] => CreateSend::ClientError, + ["429", "Too many requests"] => CreateSend::TooManyRequests, + ["500", "Server Error"] => CreateSend::ServerError }.each do |status, exception| context "#{status.first}, a get" do should "raise a #{exception.name} error" do