Henrik Igor
Henrik Igor

Reputation: 3

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

Getting this error when trying to deploy on Firebase.

error Each then() should return a value or throw 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.

Upvotes: 0

Views: 107

Answers (1)

HeySora
HeySora

Reputation: 916

The error means that every .then() method must return something.

If you don't care about the return value, you could return null; after your entire else block.

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)

Upvotes: 1

Related Questions