Handle fetch errors and rate limits and caching.
Waits and retry after rate limit rest time has reached.
import { stateActionHandler } from "fetch-rate-limit-util";
const response = await stateActionHandler(someURL, options);
// if rate limit occurs waits and retires
- HandlerResult
- RequestReporter
- wait
- stateActionHandler
- calculateRepeatAfter
- rateLimitHandler
- retryTimes
- retryHandler
- defaultHandler
- errorHandler
- cacheHandler
- DEFAULT_MIN_WAIT_MSECS
- DEFAULT_MAX_RETRIES
Type: Object
-
url
URL? what to fetch next -
repeatAfter
number? of milliseconds to wait befor next try -
message
string to report -
done
boolean op is finished return -
response
Response -
postprocess
boolean exec postprocess
Function to provide progress report.
Type: Function
-
url
String to be requested -
method
String http method name -
status
(String | Error) result of the last request -
nthTry
number how often have we retried
Executes fetch operation and handles response.
-
options
Object
Returns Promise<Response> from fetch
-
response
any
Returns (number | undefined) msecs to wait
- See: https://auth0.com/docs/policies/rate-limit-policy
- See: https://developer.github.com/v3/#rate-limiting
- See: https://opensource.zalando.com/restful-api-guidelines/#153
Waits and retries after rate limit reset time has reached.
Returns HandlerResult
Retry timeouts with increasing delay for each retry. Values in msecs.
Try several times with a increasing delay.
Returns HandlerResult
Postprocessing if response is ok.
Returns HandlerResult
No postprocessing.
Returns HandlerResult
Provide cached data.
Returns Promise<HandlerResult>
Minimum wait time in msecs.
Type: number
Max # of retries.
Type: number
With npm do:
npm install fetch-rate-limit-util
BSD-2-Clause