Skip to content

Commit

Permalink
Refactor into function to reduce filesize
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-el committed Oct 27, 2023
1 parent c6f4960 commit 98c2f9d
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions libraries/browser-tracker-core/src/tracker/out_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ export function OutQueueManager(
return typeof queue[0] === 'object' && 'evt' in queue[0];
};

const onRequestFailureTimeout = () => {
if (!retryFailedRequests) {
onRequestFailure?.({
events: currentBatch.slice(),
status: 0,
message: 'timeout',
});
}
currentBatch.length = 0;
};

/**
* Send event as POST request right away without going to queue. Used when the request surpasses maxGetBytes or maxPostBytes
* @param body POST request body
Expand All @@ -225,14 +236,7 @@ export function OutQueueManager(
// so we must set them here to listen for the response
const xhrTimeout = setTimeout(function () {
xhr.abort();
if (!retryFailedRequests) {
onRequestFailure?.({
events: currentBatch.slice(),
status: 0,
message: 'timeout',
});
}
currentBatch.length = 0;
onRequestFailureTimeout();
}, connectionTimeout);

xhr.onreadystatechange = function () {
Expand Down Expand Up @@ -365,17 +369,8 @@ export function OutQueueManager(
// Time out POST requests after connectionTimeout
const xhrTimeout = setTimeout(function () {
xhr.abort();

if (!retryFailedRequests) {
onRequestFailure?.({
events: currentBatch.slice(),
status: 0,
message: 'timeout',
});
removeEventsFromQueue(numberToSend);
}
onRequestFailureTimeout();
executingQueue = false;
currentBatch.length = 0;
}, connectionTimeout);

const removeEventsFromQueue = (numberToSend: number): void => {
Expand Down

0 comments on commit 98c2f9d

Please sign in to comment.