Exception: SQA::DataFetchError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/sqa/errors.rb

Overview

Raised when unable to fetch data from a data source (API, file, etc.). Wraps the original exception for debugging purposes.

Examples:

Raising with original error

begin
  response = api.fetch(ticker)
rescue Faraday::Error => e
  raise SQA::DataFetchError.new("Failed to fetch #{ticker}", original: e)
end

Accessing original error

begin
  stock = SQA::Stock.new(ticker: 'INVALID')
rescue SQA::DataFetchError => e
  puts e.message
  puts e.original_error.class if e.original_error
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, original: nil) ⇒ DataFetchError

Creates a new DataFetchError.

Parameters:

  • message (String)

    Error message describing the fetch failure

  • original (Exception, nil) (defaults to: nil)

    The original exception that was caught



34
35
36
37
# File 'lib/sqa/errors.rb', line 34

def initialize(message, original: nil)
  @original_error = original
  super(message)
end

Instance Attribute Details

#original_errorException? (readonly)

Returns The original exception that caused this error.

Returns:

  • (Exception, nil)

    The original exception that caused this error



28
29
30
# File 'lib/sqa/errors.rb', line 28

def original_error
  @original_error
end