Exception: TwelvedataRuby::ResponseError

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

Constant Summary collapse

API_ERROR_CODES_MAP =
{
  400 => "BadRequestResponseError",
  401 => "UnauthorizedResponseError",
  403 => "ForbiddenResponseError",
  404 => "NotFoundResponseError",
  414 => "ParameterTooLongResponseError",
  429 => "TooManyRequestsResponseError",
  500 => "InternalServerResponseError"
}.freeze
HTTP_ERROR_CODES_MAP =
{
  404 => "PageNotFoundResponseError",
}.freeze

Constants inherited from Error

Error::DEFAULT_MSGS

Instance Attribute Summary collapse

Attributes inherited from Error

#attrs

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json:, request:, attrs: nil, message: nil, code: nil) ⇒ ResponseError

Returns a new instance of ResponseError.



66
67
68
69
70
71
72
# File 'lib/twelvedata_ruby/error.rb', line 66

def initialize(json:, request:, attrs: nil, message: nil, code: nil)
  @json = json.is_a?(Hash) ? json : {}
  @code = code || @json[:code]
  @attrs = attrs || {}
  @request = request
  super(attrs: @attrs, message: "#{@json[:message] || message}")
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



64
65
66
# File 'lib/twelvedata_ruby/error.rb', line 64

def code
  @code
end

#jsonObject (readonly)

Returns the value of attribute json.



64
65
66
# File 'lib/twelvedata_ruby/error.rb', line 64

def json
  @json
end

#requestObject (readonly)

Returns the value of attribute request.



64
65
66
# File 'lib/twelvedata_ruby/error.rb', line 64

def request
  @request
end

Class Method Details

.error_code_klass(code, error_type = :api) ⇒ Object



58
59
60
61
62
# File 'lib/twelvedata_ruby/error.rb', line 58

def self.error_code_klass(code, error_type=:api)
  error_type = :api unless %i[api http].member?(error_type)

  TwelvedataRuby::ResponseError.const_get("#{error_type.upcase}_ERROR_CODES_MAP")[code]
end