【发布时间】:2017-11-20 01:39:32
【问题描述】:
我有一个名为 findProperty 的 promise 函数,在这种情况下会像这样拒绝:
reject('ERR: Unknown propertyID or inactive property in call of newBooking');
这是我调用findProperty的处理程序:
async function main() {
var res = "";
try {
findProperty();
res = await findUser(userEmail);
res = await findUser(agentEmail);
res = await getUsers();
}
catch(err) {
console.error(err);
console.log(" newBooking: " + err);
callback( { error:true, err } );
}
}
main();
这会导致以下错误:
(node:10276) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ERR: Unknown propertyID or inactive property in call of newBooking
(node:10276) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我不明白,我得到了我的catch(err) 还不够吗?
刚刚试了一下,效果很好:
resolve('ERR: Unknown propertyID or inactive property in call of newBooking');
但这给出了错误:
reject('ERR: Unknown propertyID or inactive property in call of newBooking');
【问题讨论】:
标签: javascript node.js promise