Skip to content

Commit a1783a4

Browse files
author
Thomas Dalous
committed
fix(error): add more retry error details
1 parent 53be992 commit a1783a4

File tree

1 file changed

+8
-2
lines changed
  • clients/algoliasearch-client-ruby/lib/algolia/transport

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ 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}
43+
4244
@retry_strategy.get_tryable_hosts(call_type).each do |host|
4345
opts[:timeout] ||= get_timeout(call_type) * (host.retry_count + 1)
4446
opts[:connect_timeout] ||= @config.connect_timeout * (host.retry_count + 1)
@@ -71,10 +73,14 @@ def request(call_type, method, path, body, opts = {})
7173
raise Algolia::AlgoliaHttpError.new(response.status, decoded_error[:message])
7274
end
7375

74-
return response unless outcome == RETRY
76+
if outcome == RETRY
77+
last_retry = {host: host.url, error: response.error}
78+
else
79+
return response
80+
end
7581
end
7682

77-
raise Algolia::AlgoliaUnreachableHostError, "Unreachable hosts"
83+
raise Algolia::AlgoliaUnreachableHostError, "Unreachable hosts. Last error for #{last_retry[:host]}: #{last_retry[:error]}"
7884
end
7985

8086
private

0 commit comments

Comments
 (0)