@@ -53,19 +53,15 @@ def wait_for_api_key(key, operation, api_key = {}, max_retries = 50, timeout = -
53
53
if operation == 'update'
54
54
raise ArgumentError, '`api_key` is required when waiting for an `update` operation.' if api_key.nil?
55
55
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
67
61
end
68
62
63
+ return updated_key if equals
64
+
69
65
retries += 1
70
66
sleep(timeout.call(retries) / 1000.0)
71
67
end
@@ -76,13 +72,19 @@ def wait_for_api_key(key, operation, api_key = {}, max_retries = 50, timeout = -
76
72
while retries < max_retries
77
73
begin
78
74
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
82
82
end
83
+
83
84
retries += 1
84
85
sleep(timeout.call(retries) / 1000.0)
85
86
end
87
+
86
88
raise ApiError, "The maximum number of retries exceeded. (#{ max_retries} )"
87
89
end
88
90
0 commit comments