我的 Cloud Functions node.js 文件出现此错误:
477:4 error Each then() should return a value or throw
但是我在 then()
中返回一个值,(我返回 1
)
第 477 行是带有 if (snapshot.exists){
staging.js
function manuallyDeleteObj(objDoc, fcmToken){
return objDoc.get().then(snapshot => {
if (snapshot.exists){
return objDoc.delete().then(() => {
return 1;
}).catch(() => {
return 0;
})
}
else {
const dataMsg = { data: { type: "delete" } }
if ( !isNullOrUndefined(fcmToken) ) {
return admin.messaging().sendToDevice(fcmToken, dataMsg, options);
}
}
})
.catch(() => {
return 0;
})
}
知道问题出在哪里吗?
最佳答案
存在不返回值的代码路径。尝试填写我的问题所在的空白处:
const dataMsg = { data: { type: "delete" } }
if ( !isNullOrUndefined(fcmToken) ) {
return admin.messaging().sendToDevice(fcmToken, dataMsg, options);
}
else {
// what do you want to return here?
}
关于javascript - Node.js错误: Each then() should return a value or throw?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61167492/