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

axios-status

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-status

Network requests status tracking for Axios

  • 0.0.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Network requests status tracking for Axios

This package can be used to trace status of all Axios requests for the purpose of application-wide progress indicator

Installation:

npm install axios-status --save

Usage:

First, create a new instance of AxiosStatus, and register your axios instances with it. You can provide following options to constructor

const axiosStatus = new AxiosStatus({
  timeout: 20, // default 10
  autoRetry: true // default false
})

axiosStatus.register(axios)
axiosStatus.register(mySpecialAxiosInstance)

The autoRetry options specifies if axiosStatus should auto retry all failed requests after given timeout (seconds)

Then, you can subscribe on AxiosStatus events to be able to show them in UI.

  • The busy event has values of true / false and signals that there are XHR requests in progress
  • The offline event has values of true / false and signals that request failed because network is temporariy down
  • The timer event emits a number that signals seconds to next auto-retry
axiosStatus.on('busy', (val) => this.loadingProgress = val)
axiosStatus.on('offline', (val) => this.disconnected = val)
axiosStatus.on('timer', (val) => this.secondsToReconnect = val)

To be able to correctly run a callback on auto-retry, you need to use axiosStatus.request. It supports all axios request options, plus success callback, error callback, and instance to specify axios instance on which this request should be run.

axiosStatus.request({
  instance: mySpecialAxiosInstance,	
  method: 'get',
  url: API_URL + '/me',
  success: (res) => {
    this.user = res.data
  },
  error: (err) => {
  	throw err
  }
})

To retry manually, you can just call axiosStatus.retry() to retry all calls initiated when offline

Keywords

FAQs

Package last updated on 13 Sep 2016

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