Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nuskin/axios-util

Package Overview
Dependencies
Maintainers
5
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuskin/axios-util

An Axios utility ...

  • 2.3.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
increased by8%
Maintainers
5
Weekly downloads
 
Created
Source

@nuskin/axios-util

axios-util enables you to utilize Axios as you normally would. By default, axios-util sets the timeout to 10000ms.

Retry functionality is implemented using the axios-retry module. Utilize getRetryAxiosInstance() to obtain an Axios instance with retry capabilities. All default settings of axios-retry are applied, except for the retryDelay, which is set to axiosRetry.exponentialDelay. You can customize the retry behavior by supplying an axios-retry options object to getRetryAxiosInstance().

Installing

Using npm:

npm install @nuskin/axios-util

Using yarn:

yarn add @nuskin/axios-util

Example usage

For ESM syntax, use import:

import { axios, getRetryAxiosInstance } from '@nuskin/axios-util'

For CommonJS, use require:

const { axios, getRetryAxiosInstance } = require('@nuskin/axios-util')

Customizing Retry

To customize the retry logic, access axios-retry with ESM import syntax:

let retryDelay = process.env.AXIOS_RETRY_DELAY || 5000
const myAxiosWithRetry = getRetryAxiosInstance({
    retries: 3,
    shouldResetTimeout: true,
    retryDelay: (retryCount) => {
        return retryCount * retryDelay
    },
    retryCondition: (error) => {
        // If retry condition is not specified, by default, idempotent requests are retried
        return error.response?.status >= 500 || error.code === 'ECONNABORTED'
    },
    onRetry: (retryCount, error, requestConfig) => {
        console.log(
            {
                retryCount,
                message: error.message,
                statusCode: error.response?.status,
                statusText: error.response?.statusText,
                responseData: error.response?.data
            },
            requestConfig.metric
        )
        return true;
    }
})

Other Possibilities for axios-util

License

MIT

FAQs

Package last updated on 22 Feb 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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc