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

is-fail

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

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

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 21 Jul 2015

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