我发誓我已经做到了这一点,然后改变了一些东西,但不太明白。 我有一个带有这段代码的快速 Controller :
router.post('/', (req, res, next) => {
myModule.organizationLookup(req.body.domain).then((data) => {
res.status(200).send(data);
})
});
然后我的问题代码:myModule.js 看起来像这样:
myModule.organizationLookup = (domain) => {
async function getOrganization(domain) {
try {
return await thirdpartySDK.Company.find({domain: domain});
}
catch (err) {
console.log(err)
}
}
getOrganization(domain);
};
它总是在 Controller 中抛出错误:
类型错误:无法读取未定义的属性“then”
最佳答案
其中有一个多余的函数,您不会返回其结果
。只需删除该函数并编写
myModule.organizationLookup = async function getOrganization(domain) {
try {
return await thirdpartySDK.Company.find({domain: domain});
} catch (err) {
console.log(err)
}
};
关于javascript - Async Await 未按预期等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45497159/