You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

fetch-rate-limit-util

Package Overview
Dependencies
0
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-rate-limit-util

handle fetch errors and rate limits


Version published
Maintainers
1
Created

Readme

Source

npm License bundlejs downloads GitHub Issues Build Status Styled with prettier Commitizen friendly Known Vulnerabilities Coverage Status

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

Type: Object

Properties

  • url string? 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

RequestReporter

Function to provide progress report.

Type: Function

Properties

  • 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

wait

Parameters

stateActionHandler

Executes fetch operation and handles response.

Parameters

Returns Promise<Response> from fetch

calculateRepeatAfter

Parameters

  • response any

Returns (number | undefined) msecs to wait

rateLimitHandler

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

install

With npm do:

npm install fetch-rate-limit-util

license

BSD-2-Clause

Keywords

FAQs

Package last updated on 13 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc