I get this warning for code below and I don't understand why.
It's similar to this question: Unhandled rejection reasons (should be empty)
but ...
I'm pretty sure I am handling all errors, so why the warning?
Here is JSFiddle: http://jsfiddle.net/yoorek/jLLbR/
function run(number) {
var deferred = Q.defer();
if (number % 2) {
deferred.reject(new Error('Error for ' + number));
} else {
deferred.resolve(number);
}
return deferred.promise;
}
var promises = [], data = [1, 2, 3, 4, 5];
data.forEach(function (item) {
var promise;
promise = run(item)
.then(function (result) {
log.info('Success : ' + result);
})
.catch (function (error) {
log.info('Error Handler in loop ' + error.message);
});
promises.push(promise);
});
Q.all(promises)
.then(function () {
log.info('All Success');
})
.catch (function (error) {
log.info('Error handler for All ' + error.message);
});
This was a bug with how Q did unhandled rejections. It didn't detect unhandled rejections very well and the feature was removed.
Update your version of Q from 1.0.0 , or use Bluebird which does error tracking properly.
Here's an updated fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With