Exception: Tango::Error::ServerError

Inherits:
Tango::Error
  • Object
show all
Defined in:
lib/tango/error.rb

Direct Known Subclasses

InsFunds, InsInv, InvCredential, InvInput, SysError

Instance Attribute Summary collapse

Attributes inherited from Tango::Error

#status_code

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tango::Error

#backtrace, from_status_code, #initialize

Constructor Details

This class inherits a constructor from Tango::Error

Instance Attribute Details

#responseObject

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

Returns:

  • (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

Parameters:

  • key (Symbol)


44
45
46
# File 'lib/tango/error.rb', line 44

def [](key)
  response[key] if response
end