0
我有一個名爲findProperty
承諾的功能,在這種情況下,拒絕這樣的:未處理的承諾,拒絕嘗試
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');
所以你不能正常使用的承諾,你不希望等待一個答覆?我以爲你可以混合搭配。 – torbenrudgaard
其實你是對的@torazaburo - 一旦我把'res = await findProperty();'它工作得很好。那麼我的問題是,如何運行我所有的火,忘記承諾?我有很多地方我不想等待結果。 – torbenrudgaard
@torbenrudgaard是的。但是,你需要提供一個像findProperty()catch這樣的catch(console.log.bind(console));或者根本不拒絕他們 –