Exception: TwelvedataRuby::Error
- Inherits:
-
StandardError
- Object
- StandardError
- TwelvedataRuby::Error
- Defined in:
- lib/twelvedata_ruby/error.rb
Overview
Base error class for all TwelvedataRuby errors
Direct Known Subclasses
ConfigurationError, EndpointError, NetworkError, ResponseError
Constant Summary collapse
- DEFAULT_MESSAGES =
Default error messages for different error types
{ "EndpointError" => "Endpoint is not valid: %{invalid}", "EndpointNameError" => "`%{invalid}` is not a valid endpoint. Valid endpoints: %{valid_names}", "EndpointParametersKeysError" => "Invalid parameters: %{invalid}. Valid parameters for `%{name}`: %{parameters}", "EndpointRequiredParametersError" => "Missing required parameters: %{invalid}.\ Required for `%{name}`: %{required}", "ResponseError" => "Response error occurred", "ConfigurationError" => "Configuration error: %{message}", "NetworkError" => "Network error: %{message}", }.freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#original_error ⇒ Object
readonly
Returns the value of attribute original_error.
Instance Method Summary collapse
- #format_default_message ⇒ Object private
-
#initialize(message: nil, attributes: {}, original_error: nil) ⇒ Error
constructor
Initialize error with message and attributes.
Constructor Details
#initialize(message: nil, attributes: {}, original_error: nil) ⇒ Error
Initialize error with message and attributes
25 26 27 28 29 30 31 |
# File 'lib/twelvedata_ruby/error.rb', line 25 def initialize(message: nil, attributes: {}, original_error: nil) @attributes = attributes @original_error = original_error = || super() end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
18 19 20 |
# File 'lib/twelvedata_ruby/error.rb', line 18 def attributes @attributes end |
#original_error ⇒ Object (readonly)
Returns the value of attribute original_error.
18 19 20 |
# File 'lib/twelvedata_ruby/error.rb', line 18 def original_error @original_error end |
Instance Method Details
#format_default_message ⇒ Object (private)
35 36 37 38 39 40 41 42 |
# File 'lib/twelvedata_ruby/error.rb', line 35 def template = DEFAULT_MESSAGES[Utils.demodulize(self.class.name)] return "An error occurred" unless template format(template, **attributes) rescue KeyError => e "Error message template missing key: #{e.key}" end |