Exception: TwelvedataRuby::ResponseError
- Defined in:
- lib/twelvedata_ruby/error.rb
Overview
Base class for API response errors
Direct Known Subclasses
BadRequestResponseError, ForbiddenResponseError, InternalServerResponseError, NotFoundResponseError, PageNotFoundResponseError, ParameterTooLongResponseError, TooManyRequestsResponseError, UnauthorizedResponseError
Constant Summary collapse
- API_ERROR_CODES =
Mapping of API error codes to specific error classes
{ 400 => "BadRequestResponseError", 401 => "UnauthorizedResponseError", 403 => "ForbiddenResponseError", 404 => "NotFoundResponseError", 414 => "ParameterTooLongResponseError", 429 => "TooManyRequestsResponseError", 500 => "InternalServerResponseError", }.freeze
- HTTP_ERROR_CODES =
Mapping of HTTP error codes to specific error classes
{ 404 => "PageNotFoundResponseError", }.freeze
Constants inherited from Error
Instance Attribute Summary collapse
-
#json_data ⇒ Object
readonly
Returns the value of attribute json_data.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Attributes inherited from Error
Class Method Summary collapse
-
.error_class_for_code(code, error_type = :api) ⇒ String?
Find appropriate error class for given code and type.
Instance Method Summary collapse
-
#initialize(json_data: {}, request: nil, status_code: nil, message: nil, **options) ⇒ ResponseError
constructor
Initialize response error.
Methods inherited from Error
Constructor Details
#initialize(json_data: {}, request: nil, status_code: nil, message: nil, **options) ⇒ ResponseError
Initialize response error
117 118 119 120 121 122 123 124 |
# File 'lib/twelvedata_ruby/error.rb', line 117 def initialize(json_data: {}, request: nil, status_code: nil, message: nil, **) @json_data = json_data.is_a?(Hash) ? json_data : {} @status_code = status_code || @json_data[:code] @request = request = || @json_data[:message] || "Response error occurred" super(message: , **) end |
Instance Attribute Details
#json_data ⇒ Object (readonly)
Returns the value of attribute json_data.
109 110 111 |
# File 'lib/twelvedata_ruby/error.rb', line 109 def json_data @json_data end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
109 110 111 |
# File 'lib/twelvedata_ruby/error.rb', line 109 def request @request end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
109 110 111 |
# File 'lib/twelvedata_ruby/error.rb', line 109 def status_code @status_code end |
Class Method Details
.error_class_for_code(code, error_type = :api) ⇒ String?
Find appropriate error class for given code and type
99 100 101 102 103 104 105 106 |
# File 'lib/twelvedata_ruby/error.rb', line 99 def error_class_for_code(code, error_type = :api) case error_type when :api API_ERROR_CODES[code] when :http HTTP_ERROR_CODES[code] end end |