Exception: TwilioResource::Exception
- Inherits:
-
StandardError
- Object
- StandardError
- TwilioResource::Exception
- Defined in:
- lib/twilio_resource/exceptions.rb
Overview
Wraps Twilio exceptions with a ruby exception class. Currently supports:
- Error 21452 - No Phone Numbers Found
Direct Known Subclasses
Class Method Summary collapse
-
.find_exception(e) ⇒ Object
Given a twilio error xml response, returns the corresponding exception if it is mapped, or the xml response otherwise.
-
.twilio_exceptions ⇒ Object
Hash mapping error codes to exception classes.
Class Method Details
.find_exception(e) ⇒ Object
Given a twilio error xml response, returns the corresponding exception if it is mapped, or the xml response otherwise.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/twilio_resource/exceptions.rb', line 11 def self.find_exception(e) new_exception = if e.respond_to?(:response) exception_data = Hash.from_xml(e.response.body) code = exception_data['twilio_response'] && exception_data['twilio_response']['rest_exception'] && exception_data['twilio_response']['rest_exception']['code'] exception_klass = twilio_exceptions[code.to_i] if code exception_klass.nil? ? e : exception_klass.new else e end end |
.twilio_exceptions ⇒ Object
Hash mapping error codes to exception classes.
27 28 29 30 31 |
# File 'lib/twilio_resource/exceptions.rb', line 27 def self.twilio_exceptions { 21452 => TwilioResource::NoPhoneNumbersFoundException, } end |