Socket
Socket
Sign inDemoInstall

@argueta10/http-request-retry

Package Overview
Dependencies
23
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@argueta10/http-request-retry

Request retry es la interfaz de axios implementando 3 nuevos parametros.


Version published
Maintainers
1
0

Weekly downloads

Readme

Source

Request Retry

Request retry is the axios interface implementing 3 new parameters [fallbackResponse, cache, maxRetry].

  • fallbackResponse

In case the request fails, it returns the object stored in the fallbackResponse parameter:

import * as rp from 'request-retry';

const options = {
  url: `${Env.get('API_URL')}`,
  headers: { 'Content-Type': 'application/json' },
  fallbackResponse: []
}

return rp.get(options) //in case it fails the object is returned []

Or also, if the request fails, execute a function that will receive the error and the options used to make the request as the only parameter.

import * as rp from 'request-retry';

const options = {
  url: `${Env.get('API_URL')}`,
  headers: { 'Content-Type': 'application/json' },
  fallbackResponse: (e, data) => e.response.status === 400 ? [] : ['fake'],
}

return rp.get(options) //in case it fails, the function passed by parameter will be executed
  • cache

Cache the service response in case the http code is 200:

import * as rp from 'request-retry';

const options = {
  url: `${Env.get('API_URL')}`,
  headers: { 'Content-Type': 'application/json' },
  cache: 1
}

return rp.get(options) 
  • maxRetry

If the error code is 504 or 503, the request is retried the configured number of times:

import * as rp from 'request-retry';

const options = {
  url: `${Env.get('API_URL')}`,
  headers: { 'Content-Type': 'application/json' },
  maxRetry: 3
}

return rp.get(options) 

FAQs

Last updated on 10 Aug 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc