From c2139493649d9a5f410b1aa1707db92ba3e8e5eb Mon Sep 17 00:00:00 2001 From: Greg Leonard <45019882+greg-el@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:45:26 +0100 Subject: [PATCH] Check retryFailures in onreadystatechange --- .../src/tracker/out_queue.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/libraries/browser-tracker-core/src/tracker/out_queue.ts b/libraries/browser-tracker-core/src/tracker/out_queue.ts index a9ad9304a..a2e027fe1 100644 --- a/libraries/browser-tracker-core/src/tracker/out_queue.ts +++ b/libraries/browser-tracker-core/src/tracker/out_queue.ts @@ -349,10 +349,7 @@ export function OutQueueManager( numberToSend = 1; } - // Time out POST requests after connectionTimeout - const xhrTimeout = setTimeout(function () { - xhr.abort(); - + const checkRetryFailures = () => { if (retryFailures) { LOG.warn(`Request failed, retrying.`); } else { @@ -360,6 +357,13 @@ export function OutQueueManager( removeEventsFromQueue(numberToSend); } executingQueue = false; + }; + + // Time out POST requests after connectionTimeout + const xhrTimeout = setTimeout(function () { + xhr.abort(); + + checkRetryFailures(); }, connectionTimeout); const removeEventsFromQueue = (numberToSend: number): void => { @@ -383,13 +387,19 @@ export function OutQueueManager( clearTimeout(xhrTimeout); if (xhr.status >= 200 && xhr.status < 300) { onPostSuccess(numberToSend); - } else { - if (!shouldRetryForStatusCode(xhr.status)) { - LOG.error(`Status ${xhr.status}, will not retry.`); - removeEventsFromQueue(numberToSend); - } - executingQueue = false; + return; + } + + if (xhr.status === 0) { + checkRetryFailures(); + return; + } + + if (!shouldRetryForStatusCode(xhr.status)) { + LOG.error(`Status ${xhr.status}, will not retry.`); + removeEventsFromQueue(numberToSend); } + executingQueue = false; } };