繁体   English   中英

Typescript promise 必须妥善处理

[英]Typescript promise must be handled properly

我有以下内容来更新我的 Firestore 文档。 但是有一个错误说promise必须妥善处理。 我已经在我的 function 中添加了 try catch ..谁能告诉我还有什么我错过的?

export const updateCustomer = functions.https.onRequest(async (req, resp) => {
    try
    {
            await db.collection('Users').where('CompanyId', '==', req.body.CompanyId)
            .where('CustomerId', '==', req.body.CustomerId)
            .get()
            .then(snapshot => {   
                 snapshot.forEach(doc => 
                     {
                         db.collection('Users').doc(doc.id).update(
                             {
                                 CustomerName : req.body.CustomerName,
                                 MobileNo : req.body.MobileNo,
                                 DOB: req.body.DateOfBirth,
                                 Email : req.body.Email,
                                 PreferredLanguage: req.body.PreferredLanguage
                             }
                         )
                     })
            })
            .catch(error => resp.status(500).send(error));   



       resp.status(200).send(req.body);
    }
    catch(error)
    {
       console.error(error);
       resp.status(500).send({ Message: error, StatusCode: '500', Status: 'Error'});
    }
})

db.collection('Users').doc(doc.id).update()返回 promise,您的代码忽略了它。 HTTP 类型 function 应该仅在所有异步调用完全完成后返回结果。 对整个事情进行尝试/捕捉将无济于事。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM