Skip to content

Commit a3caec2

Browse files
author
Thomas Dalous
committed
fix(requests): ensure last retry error message is forwarded when raised
1 parent ba53da6 commit a3caec2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/algolia/transport/transport.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def write(method, path, body = {}, opts = {})
4949
# @return [Response] response of the request
5050
#
5151
def request(call_type, method, path, body = {}, opts = {})
52+
last_retry_error = nil
53+
5254
@retry_strategy.get_tryable_hosts(call_type).each do |host|
5355
opts[:timeout] ||= get_timeout(call_type) * (host.retry_count + 1)
5456
opts[:connect_timeout] ||= @config.connect_timeout * (host.retry_count + 1)
@@ -73,10 +75,14 @@ def request(call_type, method, path, body = {}, opts = {})
7375
decoded_error = json_to_hash(response.error, @config.symbolize_keys)
7476
raise AlgoliaHttpError.new(get_option(decoded_error, 'status'), get_option(decoded_error, 'message'))
7577
end
76-
return json_to_hash(response.body, @config.symbolize_keys) unless outcome == RETRY
78+
if outcome == RETRY
79+
last_retry_error = response.error
80+
else
81+
return json_to_hash(response.body, @config.symbolize_keys)
82+
end
7783
end
7884

79-
raise AlgoliaUnreachableHostError, 'Unreachable hosts'
85+
raise AlgoliaUnreachableHostError, "Unreachable hosts. Last error: #{last_retry_error}"
8086
end
8187

8288
private

test/algolia/unit/retry_strategy_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_failure_when_all_hosts_are_down
8282
index.save_object({ objectID: 'one' })
8383
end
8484

85-
assert_equal 'Unreachable hosts', exception.message
85+
assert_includes exception.message, 'Unreachable hosts. Last error: SSL_connect'
8686
end
8787
end
8888

0 commit comments

Comments
 (0)