Exception: TwilioResource::Exception

Inherits:
StandardError
  • Object
show all
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

NoPhoneNumbersFoundException

Class Method Summary collapse

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
# File 'lib/twilio_resource/exceptions.rb', line 11

def self.find_exception(e)
  new_exception = if e.respond_to?(:response)
    exception_data = ActiveResource::Formats::TwilioFormat.decode(e.response.body)

    code = exception_data['code']
    exception_klass = twilio_exceptions[code.to_i] if code
    exception_klass.nil? ? e : exception_klass.new
  else
    e
  end
end

.twilio_exceptionsObject

Hash mapping error codes to exception classes.



24
25
26
27
28
# File 'lib/twilio_resource/exceptions.rb', line 24

def self.twilio_exceptions
  {
    21452 => TwilioResource::NoPhoneNumbersFoundException,
  }
end