Skip to content

Commit e84f5e5

Browse files
author
Thomas Dalous
committed
fix(error): add list of retry errors
1 parent d1b3dd9 commit e84f5e5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

clients/algoliasearch-client-ruby/lib/algolia/error.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ class AlgoliaError < StandardError
1010
# Used when hosts are unreachable
1111
#
1212
class AlgoliaUnreachableHostError < AlgoliaError
13+
attr_reader :errors
14+
15+
def initialize(message, errors = [])
16+
super(message)
17+
@errors = errors
18+
end
1319
end
1420

1521
# An exception class raised when the REST API returns an error.

clients/algoliasearch-client-ruby/lib/algolia/transport/transport.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def initialize(config, requester)
3939
# @return [Response] response of the request
4040
#
4141
def request(call_type, method, path, body, opts = {})
42-
last_retry = {host: nil, error: nil}
42+
retry_errors = []
4343

4444
@retry_strategy.get_tryable_hosts(call_type).each do |host|
4545
opts[:timeout] ||= get_timeout(call_type) * (host.retry_count + 1)
@@ -74,13 +74,13 @@ def request(call_type, method, path, body, opts = {})
7474
end
7575

7676
if outcome == RETRY
77-
last_retry = {host: host.url, error: response.error}
77+
retry_errors << {host: host.url, error: response.error}
7878
else
7979
return response
8080
end
8181
end
8282

83-
raise Algolia::AlgoliaUnreachableHostError, "Unreachable hosts. Last error for #{last_retry[:host]}: #{last_retry[:error]}"
83+
raise Algolia::AlgoliaUnreachableHostError.new("Unreachable hosts. Last error for #{retry_errors.last[:host]}: #{retry_errors.last[:error]}", retry_errors)
8484
end
8585

8686
private

0 commit comments

Comments
 (0)