circuit-breaker-as-promised
v1.1.0
Published
Hysterix-like circuit breaker with promise api
Downloads
76
Readme
circuit-breaker-as-promised
Hysterix-like circuit breaker for Javascript which wraps circuit-breaker-js and uses promises (via bluebird)
Installation
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)
})