Exception: TwelvedataRuby::ResponseError
- Defined in:
- lib/twelvedata_ruby/error.rb
Direct Known Subclasses
BadRequestResponseError, ForbiddenResponseError, InternalServerResponseErro, NotFoundResponseError, PageNotFoundResponseError, ParameterTooLongResponseError, TooManyRequestsResponseError, UnauthorizedResponseError
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
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Attributes inherited from Error
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json:, request:, attrs: nil, message: nil, code: nil) ⇒ ResponseError
constructor
A new instance of ResponseError.
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] || }") end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
64 65 66 |
# File 'lib/twelvedata_ruby/error.rb', line 64 def code @code end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
64 65 66 |
# File 'lib/twelvedata_ruby/error.rb', line 64 def json @json end |
#request ⇒ Object (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 |