I has the following to update my firestore document. But there is an error saying that promise must be handled properly. I already added in try catch in my function..Can anyone advise what else I missed out?
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()
returns a promise, and your code is ignoring it. An HTTP type function should only return a result after all asynchronous calls are fully complete. Putting a try/catch around the whole thing will not help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.