Skip to content

Commit

Permalink
Check retryFailures in onreadystatechange
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-el committed Oct 23, 2023
1 parent 8ffd557 commit c213949
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions libraries/browser-tracker-core/src/tracker/out_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,21 @@ 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 {
LOG.error(`Request failed and retryFailures is false, will not retry.`);
removeEventsFromQueue(numberToSend);
}
executingQueue = false;
};

// Time out POST requests after connectionTimeout
const xhrTimeout = setTimeout(function () {
xhr.abort();

checkRetryFailures();
}, connectionTimeout);

const removeEventsFromQueue = (numberToSend: number): void => {
Expand All @@ -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;
}
};

Expand Down

0 comments on commit c213949

Please sign in to comment.