request-catcher

1.1.0 • Public • Published

request catcher

npm NPM

This is the ajax request catcher, and confirm some info or do some thing.

Install

npm i -S request-catcher

Simple to use

import rc from 'request-catcher'

rc({
  timeout: 1000,
  onRequestWorking ({ xhr, url, status }) {
    if (status === 'pending') {

    } else if (status === 'loading') {

    } else if (status === 'loaded') {

    }
  },
  onRequestTimeout ({ xhr, url }) {
    // do something
  },
})

configure

  • timeout: default is 1000ms.
  • pendingTimeout: default is timeout, set it the timeout will be invalid.
  • loadingTimeout: default is timeout, set it the timeout will be invalid.
  • urlWhiteLists: url in urlWhiteLists won't be catched.
  • hook: onRequestWorking({ xhr, url, status }) -> if time greater than timeout callback will be do something on pending/loading/loaded.
  • hook: onRequestTimeout({ xhr, url }) -> callback do some thing on timeout.

Readme

Keywords

Package Sidebar

Install

npm i request-catcher

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

4.4 kB

Total Files

4

Last publish

Collaborators

  • maxlasting