vigor-fetch 5.2.0 → 5.4.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 +12 -9
- package/dist/index.cjs +1 -2822
- package/dist/index.d.cts +70 -68
- package/dist/index.d.ts +70 -68
- package/dist/index.js +1 -2717
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -145,14 +145,16 @@ vigor.guards.fetch(err) // isVigorFetchError
|
|
|
145
145
|
vigor.guards.all(err) // isVigorAllError
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
A request that runs out of attempts fails with `RETRY_EXHAUSTED`, and the error that actually happened (a `FETCH_FAILED`, a `TIMED_OUT`, ...) sits in its `data.error`. To reach it, pass a callback as the third argument, with the code (or an array of codes) as the second. The guard then looks at the error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`, then `cause`, and calls the callback with the first match, typed for its code. It returns what the callback returns, or `undefined` when nothing matches:
|
|
149
149
|
|
|
150
150
|
```ts
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
vigor.guards.fetch(err, "FETCH_FAILED", failed => {
|
|
152
|
+
failed.data.status // found even when wrapped in RETRY_EXHAUSTED
|
|
153
|
+
})
|
|
154
|
+
const status = vigor.guards.fetch(err, ["FETCH_FAILED", "TIMED_OUT"], e => e.code) // "FETCH_FAILED" | "TIMED_OUT" | undefined
|
|
153
155
|
```
|
|
154
156
|
|
|
155
|
-
|
|
157
|
+
Without a callback the guard only checks the error you pass, as before: it narrows its argument, and that argument is still the wrapper. So `vigor.guards.fetch(err, "FETCH_FAILED")` is `false` for a `RETRY_EXHAUSTED`, and `vigor.guards.fetch(err, "RETRY_EXHAUSTED")` is how you ask "did we give up retrying?".
|
|
156
158
|
|
|
157
159
|
---
|
|
158
160
|
|
|
@@ -829,7 +831,7 @@ try {
|
|
|
829
831
|
|
|
830
832
|
`VigorRetryErrors` & co. are unions with **one member per error code**, so narrowing by `code` also narrows `data` to that code's payload. The `{} | null | undefined` tail is everything Vigor didn't create — an error your own target or middleware threw, an abort reason, a network `TypeError`, or even a bare `throw null`. It's there because those really do reach you: a `cancelRetry()`/`breakRetry()`/abort path returns your error as-is, rather than wrapping it.
|
|
831
833
|
|
|
832
|
-
Narrow with the exported guards — `isVigorRetryError`, `isVigorParseError`, `isVigorFetchError`, `isVigorAllError` (or `vigor.guards.*`). To reach an error wrapped by `RETRY_EXHAUSTED`,
|
|
834
|
+
Narrow with the exported guards — `isVigorRetryError`, `isVigorParseError`, `isVigorFetchError`, `isVigorAllError` (or `vigor.guards.*`). To reach an error wrapped by `RETRY_EXHAUSTED`, pass a callback (see [`vigor.guards`](#vigorguards)):
|
|
833
835
|
|
|
834
836
|
```ts
|
|
835
837
|
const res = await vigor.retry(task).requestVerbose();
|
|
@@ -914,10 +916,11 @@ With an [API map](#route-descriptions) route that declares failure `responses`,
|
|
|
914
916
|
```ts
|
|
915
917
|
const res = await api.route("POST /users").body("overwrite", { name: "a" }).requestVerbose()
|
|
916
918
|
if (!res.success) {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
919
|
+
isVigorFetchError(res.error, "FETCH_FAILED", err => { // unwraps RETRY_EXHAUSTED if needed
|
|
920
|
+
if (err.data.status === 422) {
|
|
921
|
+
err.data.parsed // { fields: Record<string, string> } | undefined
|
|
922
|
+
}
|
|
923
|
+
})
|
|
921
924
|
}
|
|
922
925
|
```
|
|
923
926
|
|