@@ -150,22 +150,24 @@ def _do_fetch_with_retry(url, request_body, retry_config, timeout)
150150 # Returns:
151151 # The variation ID from the response.
152152
153- attempt = 0
154153 backoff = retry_config . initial_backoff
155- begin
156- _do_fetch ( url , request_body , timeout )
157- rescue => e
158- if attempt < retry_config . max_retries
159- @logger . log ( Logger :: INFO , "Retrying CMAB request ( attempt #{ attempt + 1 } ) after #{ backoff } seconds..." )
160- Kernel . sleep ( backoff )
161- attempt += 1
162- backoff = [ retry_config . initial_backoff * ( retry_config . backoff_multiplier **attempt ) , retry_config . max_backoff ] . min
163- retry
164- else
165- @logger . log ( Logger :: ERROR , "Max retries exceeded for CMAB request: #{ e . message } " )
166- raise Optimizely :: CmabFetchError , "CMAB decision fetch failed ( #{ e . message } )."
154+ ( 0 .. retry_config . max_retries ) . each do | attempt |
155+ begin
156+ _do_fetch ( url , request_body , timeout )
157+ rescue StandardError => e
158+ if attempt < retry_config . max_retries
159+ @logger . log ( Logger :: INFO , "Retrying CMAB request (attempt #{ attempt + 1 } ) after #{ backoff } seconds..." )
160+ Kernel . sleep ( backoff )
161+ backoff = [ backoff * ( retry_config . backoff_multiplier **( attempt + 1 ) ) , retry_config . max_backoff ] . min
162+ else
163+ @logger . log ( Logger :: ERROR , "Max retries exceeded for CMAB request: #{ e . message } " )
164+ raise Optimizely :: CmabFetchError , "CMAB decision fetch failed ( #{ e . message } )."
165+ end
167166 end
168167 end
168+ error_message = Optimizely ::Helpers ::Constants ::CMAB_FETCH_FAILED % 'Exhausted all retries for CMAB request.'
169+ @logger . log ( Logger ::ERROR , error_message )
170+ raise Optimizely ::CmabFetchError , error_message
169171 end
170172 end
171173
0 commit comments