-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fetcher): retry middleware (#29)
A new middleware for retrying fetch requests when `response.ok` is `false`. This middleware was designed to work on a per-endpoint basis. This means that it should be added immediately after the endpoint function. ``` import { createApi, requestMonitor, fetcher, fetchRetry } from 'saga-query'; const api = createApi(); api.use(requestMonitor()); api.use(api.routes()); api.use(fetcher()); const fetchUsers = api.get('/users', [ function* (ctx, next) { // ... yield next(); // ... }, fetchRetry(), ]) ``` It also supports a backoff function as a parameter. The function signature is `(attempt: number) => number`, the result of which is how long to delay the next fetch attempt. If a negative number is provided then we stop retrying.
- Loading branch information
Showing
3 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters