Skip to content

Commit d0d48b9

Browse files
author
Thomas Dalous
committed
fix(requests): add host to last error
1 parent a3caec2 commit d0d48b9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/algolia/transport/transport.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ 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
52+
last_retry = {host: nil, error: nil}
5353

5454
@retry_strategy.get_tryable_hosts(call_type).each do |host|
5555
opts[:timeout] ||= get_timeout(call_type) * (host.retry_count + 1)
@@ -76,13 +76,13 @@ def request(call_type, method, path, body = {}, opts = {})
7676
raise AlgoliaHttpError.new(get_option(decoded_error, 'status'), get_option(decoded_error, 'message'))
7777
end
7878
if outcome == RETRY
79-
last_retry_error = response.error
79+
last_retry = {host: host.url, error: response.error}
8080
else
8181
return json_to_hash(response.body, @config.symbolize_keys)
8282
end
8383
end
8484

85-
raise AlgoliaUnreachableHostError, "Unreachable hosts. Last error: #{last_retry_error}"
85+
raise AlgoliaUnreachableHostError, "Unreachable hosts. Last error for #{last_retry[:host]}: #{last_retry[:error]}"
8686
end
8787

8888
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_includes exception.message, 'Unreachable hosts. Last error: SSL_connect'
85+
assert_includes exception.message, 'Unreachable hosts. Last error for 0.0.0.0: SSL_connect'
8686
end
8787
end
8888

0 commit comments

Comments
 (0)