Exception: FetchUtil::ParallelFetcher::ParallelFetchError

Inherits:
Error
  • Object
show all
Defined in:
lib/fetch_util/parallel_fetcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(failures, results = nil) ⇒ ParallelFetchError

Returns a new instance of ParallelFetchError.



10
11
12
13
14
# File 'lib/fetch_util/parallel_fetcher.rb', line 10

def initialize(failures, results = nil)
  @failures = failures.freeze
  @results = results&.freeze
  super(self.class.build_message(@failures))
end

Instance Attribute Details

#failuresObject (readonly)

Returns the value of attribute failures.



8
9
10
# File 'lib/fetch_util/parallel_fetcher.rb', line 8

def failures
  @failures
end

#resultsObject (readonly)

Returns the value of attribute results.



8
9
10
# File 'lib/fetch_util/parallel_fetcher.rb', line 8

def results
  @results
end

Class Method Details

.build_message(failures) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/fetch_util/parallel_fetcher.rb', line 20

def self.build_message(failures)
  preview = failures.first(3).map do |failure|
    label = failure.url || "<initialization>"
    "#{label} (#{failure.error.class}: #{failure.error.message})"
  end.join(", ")
  suffix = failures.length > 3 ? ", +#{failures.length - 3} more" : ""
  "parallel fetch failed for #{failures.length} URLs: #{preview}#{suffix}"
end

Instance Method Details

#errorsObject



16
17
18
# File 'lib/fetch_util/parallel_fetcher.rb', line 16

def errors
  @failures.map(&:error)
end