1.1.0 • Published 9 years ago

circuit-breaker-as-promised v1.1.0

Weekly downloads
42
License
MIT
Repository
github
Last release
9 years ago

circuit-breaker-as-promised

js-standard-style Circle CI Dependency Status

Hysterix-like circuit breaker for Javascript which wraps circuit-breaker-js and uses promises (via bluebird)

Installation

npm install --save circuit-breaker-as-promised

Usage

var request = require('http-as-promised')
var wrapWithBreaker = require('circuit-breaker-as-promised')
var BreakerOpen = wrapWithBreaker.BreakerOpen

var breakerRequest = wrapWithBreaker(request)

... Use as normal

breakerRequest('http://lol.com')
.catch(BreakerOpen, function () {
  // Do stuff if you need to know when the breaker is open
})

You often don't want, e.g., http client errors, to trip the breaker, but still reject the returned promise as in the following example.

var breakerRequest = wrapWithBreaker(request, function (res) {
  return res.catch(request.error.client)
})