fetch-rate-limit-util
v4.4.0
Published
handle fetch errors and rate limits
Downloads
1,796
Readme
fetch-rate-limit-util
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
API
Table of Contents
- HandlerResult
- RequestReporter
- wait
- stateActionHandler
- calculateRepeatAfter
- rateLimitHandler
- retryTimes
- retryHandler
- redirectHandler
- defaultHandler
- errorHandler
- cacheHandler
- DEFAULT_MIN_WAIT_MSECS
- DEFAULT_MAX_RETRIES
- defaultOptions
HandlerResult
Type: Object
Properties
url
string? what to fetch nextrepeatAfter
number? of milliseconds to wait befor next trymessage
string? to reportdone
boolean op is finished returnresponse
Responsepostprocess
boolean exec postprocess
RequestReporter
Function to provide progress report.
Type: Function
Properties
url
string to be requestedmethod
string http method namestatus
(string | Error) result of the last requestnthTry
number how often have we retried
wait
Parameters
stateActionHandler
Executes fetch operation and handles response.
Parameters
options
Object
Returns Promise<Response> from fetch
calculateRepeatAfter
Parameters
response
any
Returns (number | undefined) msecs to wait
rateLimitHandler
- 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.
Parameters
Returns HandlerResult
retryTimes
Retry timeouts with increasing delay for each retry. Values in msecs.
retryHandler
Try several times with a increasing delay.
Parameters
Returns HandlerResult
redirectHandler
Redirect to given header location.
Parameters
Returns HandlerResult
defaultHandler
Postprocessing if response is ok.
Parameters
Returns HandlerResult
errorHandler
No postprocessing.
Parameters
Returns HandlerResult
cacheHandler
Provide cached data.
Parameters
Returns Promise<HandlerResult>
DEFAULT_MIN_WAIT_MSECS
Minimum wait time in msecs.
Type: number
DEFAULT_MAX_RETRIES
Max # of retries.
Type: number
defaultOptions
Default options
install
With npm do:
npm install fetch-rate-limit-util
license
BSD-2-Clause