From 8774a44715e37b594c23807108cfec00ef4cd124 Mon Sep 17 00:00:00 2001 From: scgreenhalgh Date: Sat, 20 Jan 2024 13:26:54 +0800 Subject: [PATCH] Fixed the function fetchWithRetries to correctly retry if there is also a response from the API which is not in the status code 2XX range. Previously it would not retry if it returned any status code and only caught connection errors/network errors. --- streaming-client-api.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/streaming-client-api.js b/streaming-client-api.js index dd972561..36a478f4 100644 --- a/streaming-client-api.js +++ b/streaming-client-api.js @@ -286,7 +286,12 @@ const maxDelaySec = 4; async function fetchWithRetries(url, options, retries = 1) { try { - return await fetch(url, options); + const res = await fetch(url, options); + if(res.status >= 200 && res.status <= 299) { + return res; + } else { + throw new Error(`Response status ${res.status}`); + } } catch (err) { if (retries <= maxRetryCount) { const delay = Math.min(Math.pow(2, retries) / 4 + Math.random(), maxDelaySec) * 1000;