【发布时间】:2021-12-02 10:34:52
【问题描述】:
有人可以帮我弄清楚我做错了什么吗?我想在继续我的函数之前先检查一个文档是否存在,如果它不存在,我会抛出一个错误。但是这个错误永远不会被抓住?这是我要抛出错误的函数:
class StoreGateway {
async addCustomerToStore(
customerId: string
) {
const customer = await fb.customersCollection.doc(customerId).get();
if (customer.exists) {
//do other stuff
} else {
console.log("customer didn't exist")
return new Error("customer didn't exist");
}
}
}
以及我如何调用函数:
StoreGateway.addCustomerToStore(
req.params.customerId
)
.then(() => {
res
.status(200)
.json("Success");
})
.catch((err) => {
res.status(500).json(err);
});
}
现在如果文档不存在,控制台会打印“客户不存在”,但我从未得到状态 500。
【问题讨论】:
标签: typescript firebase google-cloud-firestore promise