Socket
Socket
Sign inDemoInstall

is-fail

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    is-fail

Tiny package implementing multiple strategies to verify if an HTTP request was failed


Version published
Weekly downloads
762
decreased by-17.8%
Maintainers
1
Install size
6.71 kB
Created
Weekly downloads
 

Readme

Source

is-fail Build Status NPM

Tiny and dependency-free node.js/io.js package implementing multiple strategies to verify if an HTTP request was failed, checking both error and HTTP response code.

Useful to combine as part of a retry/backoff logic. Also allows you to plug in additional strategies.

Installation

npm install is-fail --save

Usage

Simple usage as part of a retry mechanism

const http = require('http')
const isFail = require('is-fail')()

function doRequest() {
  http.request('http://inconsistent-server', function (res) {
    if (isFail(null, res)) {
      return doRequest() // retry!
    }
    console.error('Response received')
  })
  .on('error', function (err) {
    if (isFail(err)) {
      return doRequest() // retry!
    }
    console.error('The request failed')
  })
}

doRequest()

Plug in additional strategies

const http = require('http')
const isFail = require('is-fail')()

function notFoundStrategy(err, res) {
  return res.statusCode === 404
}

const checkFail = isFail([ notFoundStrategy ])

http.request('http://inconsistent-server', function (res) {
  if (checkFail(null, res)) {
    console.log('Failed request!')
  }
})

API

isFail([ strategies ]) => Function(err, res) => Boolean
isFail.strategies = Array[ Strategy ]
isFail.check(strategies, err, res) => Boolean
isFail.errors = Array[ ErrorStrategy ]
isFail.status = Array[ StatusStrategy ]

License

MIT - Tomas Aparicio

Keywords

FAQs

Last updated on 21 Jul 2015

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