I'm using bluebird for promises, but also using a library that returns a non-bluebird promise. I want to use
.asCallback
Promise.resolve
then/catch
new Promise(resolve,reject)
module.exports.count = function(params, done){
var promise = client.count({
"index": config.search.index + "_" + params.index
}).then(function(response){
logger.debug(response);
}).catch(function(e){
logger.error(e);
});
return Promise.resolve(promise).asCallback(done);
Promise.resolve
does propagate errors. Your problem seems to be that catch
handles them before they could reach the resolve
. You should be doing
function count(params, done){
return Promise.resolve(client.count({
"index": config.search.index + "_" + params.index
})).then(function(response){
logger.debug(response);
return response; // important!
}, function(e){
logger.error(e);
throw e; // important!
}).asCallback(done);
}