[英]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.