Comments (11)
Just FYI I already implemented timeout and retry locally. Just need to push it up. I definitely need some help with tests.
from frisbee.
I pushed my work in progress by the way at 38d2252 if anyone wants to help out with it.
I would love help writing tests for it. Timeouts/retries all need tested.
from frisbee.
Yeah @antgel, you would be able to refresh JWT token in retryFn
.
@akmjenkins I'll gladly award you the bounty if you can open a PR for this https://github.com/niftylettuce/bug-bounties/issues/5
from frisbee.
Also, per #92 we should allow a custom callback function to be called on retries, which would allow JWT refresh tokens to be updated for example.
from frisbee.
My fetch-retry approach was to leave it entirely up to the user (no opinions based on server response codes). It could be passed into a base frisbee instance or individual requests. The API was pretty straightforward:
{
retries: number of times to retry,
retryOn: [array of status codes],
retryFn?: async function to execute between each retry
retryTimeout?: ms to wait in between retries (sensible default - like 1000ms, ignored if retryFn is supplied)
}
The only tricky parts were those you pointed out - don't retry if the AbortController.signal.aborted === true
The retryFn
was especially helpful because it allows the user to do absolutely anything they want (like refresh JWT) in between retries.
Would an API like this work?
from frisbee.
I like the simplicity of that - but I think that you could eliminate retryOn
and have that logic be up to the user in retryFn
. Then we could make a default retryFn
that checks against isRetryAllowed
was true
OR if status code was 429, 502, 503, or 504, AND ALSO checks against the Retry-After header if it existed.
from frisbee.
Great to see the activity around here! :) I don't mind that #86 was closed in favour of this, but does the above issue description include relevant details to handle that scenario? (Retrying a request after refreshing JWT access token.)
from frisbee.
Oops, I missed it, it was in #92 (comment). :)
from frisbee.
We should also use https://github.com/sindresorhus/p-queue to create a queue of requests that can be processed.
from frisbee.
What's left:
- Write tests for timeout
- Write tests for retry
- Try to get 100% code coverage
- Any instance of polyfill.io need to have proper listing of polyfills (e.g. 38d2252#diff-eacf331f0ffc35d4b482f1d15a887d3bR15 is empty right now)
- Ensure
timeout
,retry
,retryStatusCodes
,retryMethods
,retryAfterStatusCodes
,handleRetry
are documented - There is a
queue
option I added but it's not being used, so either remove that or add support for queue (e.g. via https://github.com/sindresorhus/p-queue)
from frisbee.
Related Issues (20)
- Breaking changes in v3 HOT 2
- Could not find a declaration file for module Frisbee HOT 1
- How can i modify options in request interceptor? HOT 1
- Is there a way to pass `insecureHTTPParser` configuration to request? HOT 4
- `fetch-api` npm package name maintenance question
- http methods not available in jest tests HOT 1
- Rewrite codebase after removing xo rules that are turned off HOT 1
- Error / stack trace whenever API returns non-ok response HOT 2
- Retrying request after refreshing JWT access token in response interceptor HOT 7
- TypeScript definiton HOT 2
- .get() method strips trailing slash when GET params are passed in body HOT 2
- Feature: Follow redirects and add cookie support out of the box HOT 1
- Feature: Support GZIP/compression out of the box
- Feature: Hooks HOT 1
- Error: unsupported BodyInit type when attempting to post data to endpoint accepting the "application/x-www-form-urlencoded" content-type HOT 6
- How download a image with Frisbee?
- api.auth API should accept a function instead of static singleton string HOT 1
- Possible race conditions
- React Native use frisbee get api not work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from frisbee.