I'm trying to use the promise-circuitbreaker node module. I am able to pass a parameter to the called function, however, I am unable to have the called function return a value back. Furthermore, I keep getting a timeout which I don't understand. I am obviously missing something, however I can't find any solution in the docs (http://pablolb.github.io/promise-circuitbreaker/)
I've made a very simple sample app to show my difficulties:
var CircuitBreaker = require('promise-circuitbreaker');
var TimeoutError = CircuitBreaker.TimeoutError;
var OpenCircuitError = CircuitBreaker.OpenCircuitError;
function testFcn(input, err) {
console.log('Received param: ', input);
//err('This is an error callback');
return 'Value to return';
}
var cb = new CircuitBreaker(testFcn);
var circuitBreakerPromise = cb.exec('This param is passed to the function');
circuitBreakerPromise.then(function (response) {
console.log('Never reach here:', response);
})
.catch(TimeoutError, function (error) {
console.log('Handle timeout here: ', error);
})
.catch(OpenCircuitError, function (error) {
console.log('Handle open circuit error here');
})
.catch(function (error) {
console.log('Handle any error here:', error);
})
.finally(function () {
console.log('Finally always called');
cb.stopEvents();
});
The output I get from this is:
Received param: This param is passed to the function
Handle timeout here: { [TimeoutError: Timed out after 3000 ms] name: 'TimeoutError', message: 'Timed out after 3000 ms' }
Finally always called
In my case, I want a simple string to be returned. I don't want a timeout error.
If I uncomment the line //err('This is an error callback') in testFcn(), I get the following output:
Received param: This param is passed to the function
Handle any error here: This is an error callback
Finally always called
So it appears that the 2nd parameter in the called function is for error handling.
Any help would be greatly appreciated.