Skip to content

Commit

Permalink
Set code error in RequestError exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael committed Mar 15, 2012
1 parent 68c3bd7 commit ed464aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 1 addition & 5 deletions lib/twilio-ruby/rest/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,7 @@ def connect_and_send(request) # :doc:
end
end
if response.kind_of? Net::HTTPClientError
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
raise Twilio::REST::RequestError.exception(object['message'], object['code'])
end
object
end
Expand Down
11 changes: 8 additions & 3 deletions lib/twilio-ruby/rest/errors.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module Twilio
module REST
class ServerError < StandardError; end
class RequestError < StandardError; end
class InvalidNumber < RequestError; end
class InternationalSmsUnavailable < RequestError; end

class RequestError< StandardError
attr_reader :code
def initialize(msg, code=nil);
super(msg);
@code = code;
end
end
end
end

0 comments on commit ed464aa

Please sign in to comment.