@wordpress/upload-media
Version:
Core media upload logic.
46 lines (45 loc) • 1.27 kB
JavaScript
// packages/upload-media/src/store/utils/retry.ts
function calculateRetryDelay(options) {
const { attempt, initialDelay, maxDelay, multiplier, jitter } = options;
const exponentialDelay = initialDelay * Math.pow(multiplier, attempt - 1);
const cappedDelay = Math.min(exponentialDelay, maxDelay);
const jitterFactor = 1 + (Math.random() * 2 - 1) * jitter;
return Math.floor(cappedDelay * jitterFactor);
}
var RETRYABLE_MESSAGE_PATTERNS = [
/network/i,
/timeout/i,
/ECONNRESET/i,
/fetch failed/i,
/connection/i,
/socket/i,
/ETIMEDOUT/i,
/ENOTFOUND/i,
/Could not get a valid response/i,
/Failed to fetch/i,
/Load failed/i
];
function shouldRetryError(error, retryCount, maxRetries) {
if (retryCount >= maxRetries) {
return false;
}
const message = typeof error === "string" ? error : error?.message || "";
return RETRYABLE_MESSAGE_PATTERNS.some(
(pattern) => pattern.test(message)
);
}
var retryTimers = /* @__PURE__ */ new Map();
function clearRetryTimer(id) {
const pendingTimer = retryTimers.get(id);
if (pendingTimer !== void 0) {
clearTimeout(pendingTimer);
retryTimers.delete(id);
}
}
export {
calculateRetryDelay,
clearRetryTimer,
retryTimers,
shouldRetryError
};
//# sourceMappingURL=retry.mjs.map