Permalink
Browse files

Add more granurality to client errors.

* Add specific exception for invalid number and international sms unavailable errors.
* Raise these exceptions in the case the error code is 21401 or 21408 respectively.
  • Loading branch information...
1 parent dfe12fa commit 68c3bd70fc58f0c45a1d805520de1f57c8eb416a @rafael committed Mar 14, 2012
Showing with 8 additions and 2 deletions.
  1. +5 −1 lib/twilio-ruby/rest/client.rb
  2. +3 −1 lib/twilio-ruby/rest/errors.rb
@@ -258,7 +258,11 @@ def connect_and_send(request) # :doc:
end
end
if response.kind_of? Net::HTTPClientError
- raise Twilio::REST::RequestError, object['message']
+ case object['code']
+ when 21401 then raise Twilio::REST::InvalidNumber, object['message']
+ when 21408 then raise Twilio::REST::InternationalSmsUnavailable, object['message']
+ else raise Twilio::REST::RequestError, object['message']
+ end
end
object
end
@@ -1,6 +1,8 @@
module Twilio
module REST
- class RequestError < StandardError; end
class ServerError < StandardError; end
+ class RequestError < StandardError; end
+ class InvalidNumber < RequestError; end
+ class InternationalSmsUnavailable < RequestError; end
end
end

0 comments on commit 68c3bd7

Please sign in to comment.