【发布时间】:2021-04-03 18:16:40
【问题描述】:
所以在我的云函数中,我有这个 sn-p 代码:
return users_pending_update.once('value').then((snapshot) => {
if (snapshot.exists()) {
return manage(ref_date, zonesYetToBeUpdated, snapshot);
} else {
return users_tzs_ref.once('value').then((snapshot) => {
if (snapshot.exists()) {
return manage(ref_date, zonesYetToBeUpdated, snapshot);
} else {
return null;
}
}).catch((error) => {
console.error("Getting the list of values from the \"users_tzs\" node failed with error: " + error);
});
}
}).catch((error) => {
console.error("Getting the list of values from the \"users_pending_update\" node failed with error: " + error);
});
我的问题是关于您可以在代码中看到的 return null 语句。我在那里拥有它的唯一原因是因为我收到一个警告,即并非所有代码路径都返回一个值。我不需要也不关心那边的那条路。如果我使用 return Promise.reject("text") 之类的东西,警告也会消失。如果我将其保留为 return null 会有问题吗?如果是,我应该将其更改为什么?
【问题讨论】:
-
如果不了解这段代码如何适应整个函数的上下文,或者不了解达到 null 时函数的用途,很难说。请编辑问题以使其更完整。
标签: javascript firebase firebase-realtime-database promise google-cloud-functions