@@ -22964,30 +22964,37 @@ var isError = (value) => objectToString.call(value) === "[object Error]"; |
22964 | 22964 | var errorMessages = /* @__PURE__ */ new Set([ |
22965 | 22965 | "network error", |
22966 | 22966 | // Chrome |
22967 | | - "Failed to fetch", |
22968 | | - // Chrome |
22969 | 22967 | "NetworkError when attempting to fetch resource.", |
22970 | 22968 | // Firefox |
22971 | 22969 | "The Internet connection appears to be offline.", |
22972 | 22970 | // Safari 16 |
22973 | | - "Load failed", |
22974 | | - // Safari 17+ |
22975 | 22971 | "Network request failed", |
22976 | 22972 | // `cross-fetch` |
22977 | 22973 | "fetch failed", |
22978 | 22974 | // Undici (Node.js) |
22979 | | - "terminated" |
| 22975 | + "terminated", |
22980 | 22976 | // Undici (Node.js) |
| 22977 | + " A network error occurred.", |
| 22978 | + // Bun (WebKit) |
| 22979 | + "Network connection lost" |
| 22980 | + // Cloudflare Workers (fetch) |
22981 | 22981 | ]); |
22982 | 22982 | function isNetworkError(error2) { |
22983 | 22983 | const isValid = error2 && isError(error2) && error2.name === "TypeError" && typeof error2.message === "string"; |
22984 | 22984 | if (!isValid) { |
22985 | 22985 | return false; |
22986 | 22986 | } |
22987 | | - if (error2.message === "Load failed") { |
22988 | | - return error2.stack === void 0; |
| 22987 | + const { message, stack } = error2; |
| 22988 | + if (message === "Load failed") { |
| 22989 | + return stack === void 0 || "__sentry_captured__" in error2; |
| 22990 | + } |
| 22991 | + if (message.startsWith("error sending request for url")) { |
| 22992 | + return true; |
| 22993 | + } |
| 22994 | + if (message === "Failed to fetch" || message.startsWith("Failed to fetch (") && message.endsWith(")")) { |
| 22995 | + return true; |
22989 | 22996 | } |
22990 | | - return errorMessages.has(error2.message); |
| 22997 | + return errorMessages.has(message); |
22991 | 22998 | } |
22992 | 22999 |
|
22993 | 23000 | // node_modules/p-retry/index.js |
@@ -23017,6 +23024,14 @@ function validateNumberOption(name, value, { min = 0, allowInfinity = false } = |
23017 | 23024 | throw new TypeError(`Expected \`${name}\` to be \u2265 ${min}.`); |
23018 | 23025 | } |
23019 | 23026 | } |
| 23027 | +function validateFunctionOption(name, value) { |
| 23028 | + if (value === void 0) { |
| 23029 | + return; |
| 23030 | + } |
| 23031 | + if (typeof value !== "function") { |
| 23032 | + throw new TypeError(`Expected \`${name}\` to be a function.`); |
| 23033 | + } |
| 23034 | +} |
23020 | 23035 | var AbortError = class extends Error { |
23021 | 23036 | constructor(message) { |
23022 | 23037 | super(); |
@@ -23044,62 +23059,87 @@ function calculateRemainingTime(start, max) { |
23044 | 23059 | } |
23045 | 23060 | return max - (performance.now() - start); |
23046 | 23061 | } |
| 23062 | +async function delayForRetry(delay, options) { |
| 23063 | + if (delay <= 0) { |
| 23064 | + return; |
| 23065 | + } |
| 23066 | + await new Promise((resolve2, reject) => { |
| 23067 | + const onAbort = () => { |
| 23068 | + clearTimeout(timeoutToken); |
| 23069 | + options.signal?.removeEventListener("abort", onAbort); |
| 23070 | + reject(options.signal.reason); |
| 23071 | + }; |
| 23072 | + const timeoutToken = setTimeout(() => { |
| 23073 | + options.signal?.removeEventListener("abort", onAbort); |
| 23074 | + resolve2(); |
| 23075 | + }, delay); |
| 23076 | + if (options.unref) { |
| 23077 | + timeoutToken.unref?.(); |
| 23078 | + } |
| 23079 | + options.signal?.addEventListener("abort", onAbort, { once: true }); |
| 23080 | + }); |
| 23081 | +} |
23047 | 23082 | async function onAttemptFailure({ error: error2, attemptNumber, retriesConsumed, startTime, options }) { |
23048 | 23083 | const normalizedError = error2 instanceof Error ? error2 : new TypeError(`Non-error was thrown: "${error2}". You should only throw errors.`); |
23049 | 23084 | if (normalizedError instanceof AbortError) { |
23050 | 23085 | throw normalizedError.originalError; |
23051 | 23086 | } |
23052 | 23087 | const retriesLeft = Number.isFinite(options.retries) ? Math.max(0, options.retries - retriesConsumed) : options.retries; |
23053 | 23088 | const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY; |
| 23089 | + const delayTime = calculateDelay(retriesConsumed, options); |
| 23090 | + const remainingTimeBeforeCallbacks = calculateRemainingTime(startTime, maxRetryTime); |
| 23091 | + if (remainingTimeBeforeCallbacks <= 0) { |
| 23092 | + const context2 = Object.freeze({ |
| 23093 | + error: normalizedError, |
| 23094 | + attemptNumber, |
| 23095 | + retriesLeft, |
| 23096 | + retriesConsumed, |
| 23097 | + retryDelay: 0 |
| 23098 | + }); |
| 23099 | + await options.onFailedAttempt(context2); |
| 23100 | + throw normalizedError; |
| 23101 | + } |
| 23102 | + const consumeRetryContext = Object.freeze({ |
| 23103 | + error: normalizedError, |
| 23104 | + attemptNumber, |
| 23105 | + retriesLeft, |
| 23106 | + retriesConsumed, |
| 23107 | + retryDelay: retriesLeft > 0 ? delayTime : 0 |
| 23108 | + }); |
| 23109 | + const consumeRetry = await options.shouldConsumeRetry(consumeRetryContext); |
| 23110 | + const effectiveDelay = consumeRetry && retriesLeft > 0 ? delayTime : 0; |
23054 | 23111 | const context = Object.freeze({ |
23055 | 23112 | error: normalizedError, |
23056 | 23113 | attemptNumber, |
23057 | 23114 | retriesLeft, |
23058 | | - retriesConsumed |
| 23115 | + retriesConsumed, |
| 23116 | + retryDelay: effectiveDelay |
23059 | 23117 | }); |
23060 | 23118 | await options.onFailedAttempt(context); |
23061 | 23119 | if (calculateRemainingTime(startTime, maxRetryTime) <= 0) { |
23062 | 23120 | throw normalizedError; |
23063 | 23121 | } |
23064 | | - const consumeRetry = await options.shouldConsumeRetry(context); |
23065 | 23122 | const remainingTime = calculateRemainingTime(startTime, maxRetryTime); |
23066 | 23123 | if (remainingTime <= 0 || retriesLeft <= 0) { |
23067 | 23124 | throw normalizedError; |
23068 | 23125 | } |
23069 | 23126 | if (normalizedError instanceof TypeError && !isNetworkError(normalizedError)) { |
23070 | | - if (consumeRetry) { |
23071 | | - throw normalizedError; |
23072 | | - } |
23073 | | - options.signal?.throwIfAborted(); |
23074 | | - return false; |
| 23127 | + throw normalizedError; |
23075 | 23128 | } |
23076 | 23129 | if (!await options.shouldRetry(context)) { |
23077 | 23130 | throw normalizedError; |
23078 | 23131 | } |
| 23132 | + const remainingTimeAfterShouldRetry = calculateRemainingTime(startTime, maxRetryTime); |
| 23133 | + if (remainingTimeAfterShouldRetry <= 0) { |
| 23134 | + throw normalizedError; |
| 23135 | + } |
23079 | 23136 | if (!consumeRetry) { |
23080 | 23137 | options.signal?.throwIfAborted(); |
23081 | 23138 | return false; |
23082 | 23139 | } |
23083 | | - const delayTime = calculateDelay(retriesConsumed, options); |
23084 | | - const finalDelay = Math.min(delayTime, remainingTime); |
| 23140 | + const finalDelay = Math.min(effectiveDelay, remainingTimeAfterShouldRetry); |
23085 | 23141 | options.signal?.throwIfAborted(); |
23086 | | - if (finalDelay > 0) { |
23087 | | - await new Promise((resolve2, reject) => { |
23088 | | - const onAbort = () => { |
23089 | | - clearTimeout(timeoutToken); |
23090 | | - options.signal?.removeEventListener("abort", onAbort); |
23091 | | - reject(options.signal.reason); |
23092 | | - }; |
23093 | | - const timeoutToken = setTimeout(() => { |
23094 | | - options.signal?.removeEventListener("abort", onAbort); |
23095 | | - resolve2(); |
23096 | | - }, finalDelay); |
23097 | | - if (options.unref) { |
23098 | | - timeoutToken.unref?.(); |
23099 | | - } |
23100 | | - options.signal?.addEventListener("abort", onAbort, { once: true }); |
23101 | | - }); |
23102 | | - } |
| 23142 | + await delayForRetry(finalDelay, options); |
23103 | 23143 | options.signal?.throwIfAborted(); |
23104 | 23144 | return true; |
23105 | 23145 | } |
@@ -23119,6 +23159,9 @@ async function pRetry(input, options = {}) { |
23119 | 23159 | }; |
23120 | 23160 | options.shouldRetry ??= () => true; |
23121 | 23161 | options.shouldConsumeRetry ??= () => true; |
| 23162 | + validateFunctionOption("onFailedAttempt", options.onFailedAttempt); |
| 23163 | + validateFunctionOption("shouldRetry", options.shouldRetry); |
| 23164 | + validateFunctionOption("shouldConsumeRetry", options.shouldConsumeRetry); |
23122 | 23165 | validateNumberOption("factor", options.factor, { min: 0, allowInfinity: false }); |
23123 | 23166 | validateNumberOption("minTimeout", options.minTimeout, { min: 0, allowInfinity: false }); |
23124 | 23167 | validateNumberOption("maxTimeout", options.maxTimeout, { min: 0, allowInfinity: true }); |
|
Online Article Reader Icon Best Unsecured Credit Cards For Building