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.2.0
  • npm
  • Socket score

Version published
Weekly downloads
677
decreased by-39.01%
Maintainers
5
Weekly downloads
 
Created
Source

@nuskin/axios-util

axios-util allows you to use Axios in the exact same way you would use Axios by itself. By default axios-util will set the timeout to 10000ms.

Retry has been implemented with the axios-retry module. Use getRetryAxiosInstance() to get an axios instance with retry added to it. All defaults of axios-retry are used except for retryDelay. retryDelay is set to axiosRetry.exponentialDelay. You can set your own behavior by providing an axios-retry options object to getRetryAxiosInstance().

Installing

Usng npm:

npm install @nuskin/axios-util

Usng yarn:

yarn add @nuskin/axios-util

Example usage

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

// Now use axios as you normally would

Customizing retry

You can customize your retry logic by accessing axios-retry.

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

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) => {
        log.info(
            {
                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

Resources

  • Changelog could go here

License

MIT

FAQs

Package last updated on 26 Sep 2023

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