Error checking with callbacks:
dbFind('foo', function(err, data) {
if (err) throw err;
dbFind(data.id, function(err, data) {
if (err) throw err;
dbFind(data.id, function(err, data) {
if (err) throw err;
dbFind(data.id, function(err, data) {
if (err) throw err;
console.log(data);
});
});
});
});
});
Error handling with promises (using q):
Q.fcall(dbFind, 'foo')
.then(function (data) {
return Q.fcall(dbFind, data.id)
})
.then(function (data) {
return Q.fcall(dbFind, data.id)
})
.then(function (data) {
return Q.fcall(dbFind, data.id)
})
.then(function (data) {
console.log(data);
})
.catch(function (err) {
throw err;
})
.done()