Skip to content

Commit 812b6c5

Browse files
Fluf22millotp
authored andcommitted
fix(ruby): make sure to return a status code from an http error
1 parent 6b29f90 commit 812b6c5

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def request(call_type, method, path, body, opts = {})
6868
)
6969
if outcome == FAILURE
7070
decoded_error = JSON.parse(response.error, :symbolize_names => true)
71-
raise Algolia::AlgoliaHttpError.new(decoded_error[:status], decoded_error[:message])
71+
raise Algolia::AlgoliaHttpError.new(response.status, decoded_error[:message])
7272
end
7373

7474
return response unless outcome == RETRY

templates/ruby/search_helpers.mustache

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,15 @@ def wait_for_api_key(key, operation, api_key = {}, max_retries = 50, timeout = -
5353
if operation == 'update'
5454
raise ArgumentError, '`api_key` is required when waiting for an `update` operation.' if api_key.nil?
5555
while retries < max_retries
56-
begin
57-
updatad_key = get_api_key(key, request_options)
58-
updated_key_hash = updatad_key.to_hash
59-
equals = true
60-
api_key.to_hash.each do |k, v|
61-
equals &&= updated_key_hash[k] == v
62-
end
63-
64-
return updatad_key if equals
65-
rescue AlgoliaError => e
66-
raise e unless e.code == 404
56+
updated_key = get_api_key(key, request_options)
57+
updated_key_hash = updated_key.to_hash
58+
equals = true
59+
api_key.to_hash.each do |k, v|
60+
equals &&= updated_key_hash[k] == v
6761
end
6862

63+
return updated_key if equals
64+
6965
retries += 1
7066
sleep(timeout.call(retries) / 1000.0)
7167
end
@@ -76,13 +72,19 @@ def wait_for_api_key(key, operation, api_key = {}, max_retries = 50, timeout = -
7672
while retries < max_retries
7773
begin
7874
res = get_api_key(key, request_options)
79-
return res if operation == 'add'
80-
rescue AlgoliaError => e
81-
return res if operation == 'delete' && e.code == 404
75+
return res if operation == "add"
76+
rescue AlgoliaHttpError => e
77+
if e.code == 404
78+
return nil if operation == "delete"
79+
else
80+
raise e
81+
end
8282
end
83+
8384
retries += 1
8485
sleep(timeout.call(retries) / 1000.0)
8586
end
87+
8688
raise ApiError, "The maximum number of retries exceeded. (#{max_retries})"
8789
end
8890

0 commit comments

Comments
 (0)