Permalink
Browse files

Set code error in RequestError exceptions

  • Loading branch information...
1 parent 68c3bd7 commit ed464aae793ce589d4826226b453ceb69e7a2f8f @rafael committed Mar 15, 2012
Showing with 9 additions and 8 deletions.
  1. +1 −5 lib/twilio-ruby/rest/client.rb
  2. +8 −3 lib/twilio-ruby/rest/errors.rb
@@ -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
@@ -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.