Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Set code error in RequestError exceptions

  • Loading branch information...
commit ed464aae793ce589d4826226b453ceb69e7a2f8f 1 parent 68c3bd7
Rafael Chacon authored
6 lib/twilio-ruby/rest/client.rb
View
@@ -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
11 lib/twilio-ruby/rest/errors.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.