javascript - Node.js错误: Each then() should return a value or throw?

标签 javascript node.js promise google-cloud-functions eslint

我的 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/

相关文章:

javascript - 从具有 Angular 2 http 调用的函数返回 Promise,该调用返回 Observable

javascript - 我们可以模仿浏览器并使用 php 获取特定的网络请求 header 吗?

javascript - window.event.srcElement 在 IE10 中为 null

javascript - 带有 websocket 接口(interface)的数据库?

node.js - 使用 angularjs 和 sails.js 后端构建单页应用程序

java - 带有 JWT 响应的登录请求

javascript - 如何循环发出异步请求?

javascript - RxJS:如果请求很慢则显示加载

javascript - 如何在 webview android 中处理 html

javascript - 原型(prototype)继承(javascript)