我正在使用带有Q的Nodejs进行承诺。这里promise2
连接到cassandra服务器并插入一些数据。但是当数据库关闭时,它返回
{
"innerErrors": {
"127.0.0.1:9042": {
"code": "ECONNREFUSED",
"errno": "ECONNREFUSED",
"syscall": "connect"
}
},
"info": "Represents an error when a query cannot be performed because no host is available or could be reached by the driver.",
"message": "All host(s) tried for query failed. First host tried, 127.0.0.1:9042: Error: connect ECONNREFUSED. See innerErrors."
}
并正确执行deferred.reject(err)
。但不知何故,它不会陷入承诺链中的catch块(应用程序不会崩溃它只会继续)。但是如果promise1不涉及cassandra操作,拒绝它,它将陷入catch块。
如何捕获此错误?
承诺链
promise1(someData)
.then(function(result){
return promise2();
})
.then(function(result){
// deferred.resolve();
})
.catch(function(err){
// deferred.reject(err);
});
Promise2
实施
boundary.client.execute(query,fieldValues,{prepare:isPrepare}, function(err,result){
if(err){
deferred.reject(err);
}else{
deferred.resolve(result);
}