vigor-fetch 5.0.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/dist/index.cjs +47 -4
- package/dist/index.d.cts +377 -320
- package/dist/index.d.ts +377 -320
- package/dist/index.js +42 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -222,6 +222,22 @@ var VigorError = class extends Error {
|
|
|
222
222
|
Error.captureStackTrace?.(this, new.target);
|
|
223
223
|
}
|
|
224
224
|
};
|
|
225
|
+
function findInVigorErrorChain(error, match) {
|
|
226
|
+
const seen = /* @__PURE__ */ new Set();
|
|
227
|
+
const visit = (current) => {
|
|
228
|
+
if (current === null || current === void 0 || seen.has(current)) return void 0;
|
|
229
|
+
seen.add(current);
|
|
230
|
+
if (match(current)) return current;
|
|
231
|
+
if (typeof current !== "object") return void 0;
|
|
232
|
+
const data = current.data;
|
|
233
|
+
if (current instanceof VigorError && data !== null && typeof data === "object" && "error" in data) {
|
|
234
|
+
const found = visit(data.error);
|
|
235
|
+
if (found !== void 0) return found;
|
|
236
|
+
}
|
|
237
|
+
return visit(current.cause);
|
|
238
|
+
};
|
|
239
|
+
return visit(error);
|
|
240
|
+
}
|
|
225
241
|
|
|
226
242
|
// src/all/error.ts
|
|
227
243
|
var VigorAllErrorMessageFuncs = {
|
|
@@ -241,6 +257,10 @@ var VigorAllError = class extends VigorError {
|
|
|
241
257
|
function isVigorAllError(error, ...codes) {
|
|
242
258
|
return error instanceof VigorAllError && (codes.length === 0 || codes.includes(error.code));
|
|
243
259
|
}
|
|
260
|
+
function findVigorAllError(error, ...codes) {
|
|
261
|
+
const found = findInVigorErrorChain(error, (e) => isVigorAllError(e, ...codes));
|
|
262
|
+
return found === void 0 ? null : found;
|
|
263
|
+
}
|
|
244
264
|
|
|
245
265
|
// src/core/timeline.ts
|
|
246
266
|
var internalMiddlewares = /* @__PURE__ */ new WeakSet();
|
|
@@ -758,6 +778,10 @@ var VigorRetryError = class extends VigorError {
|
|
|
758
778
|
function isVigorRetryError(error, ...codes) {
|
|
759
779
|
return error instanceof VigorRetryError && (codes.length === 0 || codes.includes(error.code));
|
|
760
780
|
}
|
|
781
|
+
function findVigorRetryError(error, ...codes) {
|
|
782
|
+
const found = findInVigorErrorChain(error, (e) => isVigorRetryError(e, ...codes));
|
|
783
|
+
return found === void 0 ? null : found;
|
|
784
|
+
}
|
|
761
785
|
|
|
762
786
|
// src/retry/algorithms.ts
|
|
763
787
|
function VigorJitter(jitter) {
|
|
@@ -1462,6 +1486,10 @@ var VigorParseError = class extends VigorError {
|
|
|
1462
1486
|
function isVigorParseError(error, ...codes) {
|
|
1463
1487
|
return error instanceof VigorParseError && (codes.length === 0 || codes.includes(error.code));
|
|
1464
1488
|
}
|
|
1489
|
+
function findVigorParseError(error, ...codes) {
|
|
1490
|
+
const found = findInVigorErrorChain(error, (e) => isVigorParseError(e, ...codes));
|
|
1491
|
+
return found === void 0 ? null : found;
|
|
1492
|
+
}
|
|
1465
1493
|
|
|
1466
1494
|
// src/parse/strategies.ts
|
|
1467
1495
|
var VigorParsePolicyStrategiesBase = {
|
|
@@ -1954,6 +1982,10 @@ var VigorFetchError = class extends VigorError {
|
|
|
1954
1982
|
function isVigorFetchError(error, ...codes) {
|
|
1955
1983
|
return error instanceof VigorFetchError && (codes.length === 0 || codes.includes(error.code));
|
|
1956
1984
|
}
|
|
1985
|
+
function findVigorFetchError(error, ...codes) {
|
|
1986
|
+
const found = findInVigorErrorChain(error, (e) => isVigorFetchError(e, ...codes));
|
|
1987
|
+
return found === void 0 ? null : found;
|
|
1988
|
+
}
|
|
1957
1989
|
function adoptVigorFetchError(error, context) {
|
|
1958
1990
|
if (!(error instanceof VigorRetryError) && !(error instanceof VigorParseError)) return error;
|
|
1959
1991
|
const data = error.data;
|
|
@@ -2525,6 +2557,7 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
|
|
|
2525
2557
|
};
|
|
2526
2558
|
|
|
2527
2559
|
// src/entry/main.ts
|
|
2560
|
+
var guardWithFind = (guard, find) => Object.assign(((...args) => guard(...args)), { find });
|
|
2528
2561
|
function retryWithTarget(task) {
|
|
2529
2562
|
return new VigorRetry().target(task);
|
|
2530
2563
|
}
|
|
@@ -2569,10 +2602,10 @@ var vigorBase = {
|
|
|
2569
2602
|
}
|
|
2570
2603
|
},
|
|
2571
2604
|
guards: {
|
|
2572
|
-
retry: isVigorRetryError,
|
|
2573
|
-
parse: isVigorParseError,
|
|
2574
|
-
fetch: isVigorFetchError,
|
|
2575
|
-
all: isVigorAllError
|
|
2605
|
+
retry: guardWithFind(isVigorRetryError, findVigorRetryError),
|
|
2606
|
+
parse: guardWithFind(isVigorParseError, findVigorParseError),
|
|
2607
|
+
fetch: guardWithFind(isVigorFetchError, findVigorFetchError),
|
|
2608
|
+
all: guardWithFind(isVigorAllError, findVigorAllError)
|
|
2576
2609
|
}
|
|
2577
2610
|
};
|
|
2578
2611
|
var cloneVigor = (v) => ({
|
|
@@ -2666,6 +2699,11 @@ export {
|
|
|
2666
2699
|
createBrand,
|
|
2667
2700
|
createVigorTimelineRecorder,
|
|
2668
2701
|
index_default as default,
|
|
2702
|
+
findInVigorErrorChain,
|
|
2703
|
+
findVigorAllError,
|
|
2704
|
+
findVigorFetchError,
|
|
2705
|
+
findVigorParseError,
|
|
2706
|
+
findVigorRetryError,
|
|
2669
2707
|
isVigorAllError,
|
|
2670
2708
|
isVigorDefault,
|
|
2671
2709
|
isVigorEmpty,
|