Skip to content

Commit

Permalink
Add more granurality to client errors.
Browse files Browse the repository at this point in the history
* 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
rafael committed Mar 14, 2012
1 parent dfe12fa commit 68c3bd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/twilio-ruby/rest/client.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ def connect_and_send(request) # :doc:
end end
end end
if response.kind_of? Net::HTTPClientError 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 end
object object
end end
Expand Down
4 changes: 3 additions & 1 deletion lib/twilio-ruby/rest/errors.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,8 @@
module Twilio module Twilio
module REST module REST
class RequestError < StandardError; end
class ServerError < StandardError; end class ServerError < StandardError; end
class RequestError < StandardError; end
class InvalidNumber < RequestError; end
class InternationalSmsUnavailable < RequestError; end
end end
end end

0 comments on commit 68c3bd7

Please sign in to comment.