Suppose I have code like this, assuming db.get()
is a promisified API:
var promises = [];
for( var i = 0; i < 10; i++ ){
promises.push( getFromDatabase("age") );
}
Q.all(promises).then(function(results){
// something
},function(error){
log.error( error )
});
function getFromDatabase(property){
return db.get(property).then(function(result){
return result;
},function(error){
log.error( error )
})
}
Who'll handle the error? The function in promise chain of Q.all()
or the function in promise chain of getFromDatabase()
.
Also, if there is a top level error handler like in Q.all()
, is there a need for handling error in helper functions?