Exception: Tango::Error::ServerError
- Inherits:
-
Tango::Error
- Object
- StandardError
- Tango::Error
- Tango::Error::ServerError
- Defined in:
- lib/tango/error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Attributes inherited from Tango::Error
Class Method Summary collapse
- .from_response(body) ⇒ Object
- .raise_on?(status_code) ⇒ Boolean
-
.response_type_to_class_name(type) ⇒ Object
Convert response type to class name.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Fetches value from response by key.
Methods inherited from Tango::Error
#backtrace, from_status_code, #initialize
Constructor Details
This class inherits a constructor from Tango::Error
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
39 40 41 |
# File 'lib/tango/error.rb', line 39 def response @response end |
Class Method Details
.from_response(body) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tango/error.rb', line 53 def self.from_response(body) if body.is_a?(Hash) && body[:responseType] type = body[:responseType] class_name = response_type_to_class_name(type) if Tango::Error.const_defined?(class_name) ex = Tango::Error.const_get(class_name).new(body[:response]) else ex = new(body[:response]) end ex.response = body[:response] ex else new("Invalid response: #{body.to_s}") end end |
.raise_on?(status_code) ⇒ Boolean
35 36 37 |
# File 'lib/tango/error.rb', line 35 def self.raise_on?(status_code) 500 <= status_code && status_code < 600 end |
.response_type_to_class_name(type) ⇒ Object
Convert response type to class name
49 50 51 |
# File 'lib/tango/error.rb', line 49 def self.response_type_to_class_name(type) type.split('_').collect(&:capitalize).join('') end |
Instance Method Details
#[](key) ⇒ Object
Fetches value from response by key
44 45 46 |
# File 'lib/tango/error.rb', line 44 def [](key) response[key] if response end |