简体   繁体   English

部署Firebase云函数时出错每个then()应该返回一个值或抛出

[英]Error on deploy Firebase cloud function Each then() should return a value or throw

Any suggestions on what is wrong here? 对这里有什么问题有什么建议吗? The code is from google this tutorial from Google https://firebase.googleblog.com/2017/08/guard-your-web-content-from-abuse-with.html 该代码来自Google本教程来自Google https://firebase.googleblog.com/2017/08/guard-your-web-content-from-abuse-with.html

Getting this error when trying to deploy on Firebase. 尝试在Firebase上进行部署时出现此错误。

error Each then() should return a value or throw promise/always-return 错误每个then()应该返回一个值或抛出promise / always-return

and here is the code: 这是代码:

//recaptcha
exports.checkRecaptcha = functions.https.onRequest((req, res) => {
    const response = req.query.response;
    console.log("recaptcha response", response);
    rp({
        uri: 'https://recaptcha.google.com/recaptcha/api/siteverify',
        method: 'POST',
        formData: {
            secret: 'my_secret_key',
            response: response
        },
        json: true
    }).then(result => {
        console.log("recaptcha result", result);
        if (result.success) {
            res.send("You're good to go, human.");
        }
        else {
            res.send("Recaptcha verification failed. Are you a robot?");
        }
    }).catch(reason => {
        console.log("Recaptcha request failure", reason);
        res.send("Recaptcha request failed.");
    });
});

Thanks a lot for any help. 非常感谢您的帮助。

The error means that every .then() method must return something. 该错误意味着每个.then()方法都必须返回某些内容。

If you don't care about the return value, you could return null; 如果您不关心返回值,则可以return null; after your entire else block. 在整个else块之后。

Here, you can do this: 在这里,您可以执行以下操作:

if (result.success) {
    return res.send("You're good to go, human.");
}
return res.send("Recaptcha verification failed. Are you a robot?");

(The else is not needed because return stops the execution of the method, and thus won't execute the lines after) (不需要else ,因为return停止方法的执行,因此以后将不执行行)

暂无
暂无

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

相关问题 每个 then() 应该在 firebase 云 function 中返回一个值或抛出错误 - Each then() should return a value or throw error in firebase cloud function 在部署 Firebase 云 Function 时收到“每个都应该返回值或抛出”错误 - On Deploying the Firebase Cloud Function getting an error of “Each then should return a value or throw” 得到错误每个 then() 应该返回一个值或抛出我的 firebase function - getting error Each then() should return a value or throw in my firebase function 每个 then() 都应该返回一个值或抛出 Firebase 云函数 - Each then() should return a value or throw Firebase cloud functions 部署 Firebase 函数时出错:每个 then() 都应该返回一个值或抛出 promise/always-return - Error deploying Firebase function: Each then() should return a value or throw promise/always-return Firebase云消息传递每个then()应该返回一个值或抛出Promise / Always-Return - Firebase cloud messaging Each then() should return a value or throw promise/always-return 错误每个 then() 应该返回一个值或抛出 - Error Each then() should return a value or throw 在使用node.js中的firebase从Google云端存储中读取时,ESlint发出“每次应返回一个值或引发错误”的问题 - ESlint issue “Each then should return a value or throw” while reading from google cloud store using firebase in node.js 每个 then() 应该返回一个值或抛出 - Each then() should return a value or throw Node.js 错误:每个 then() 应该返回一个值还是抛出? - Node.js error: Each then() should return a value or throw?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM