Kai
Kai

Reputation: 25

Google Cloud res.send is not a function

The function is triggered by a Cron PubSub to pull data from an API and update a Big Query table.

It works when locally tested (npx @google-cloud/functions-framework --target pullElevate)

But results in an error (TypeError: res.send is not a function at exports.pullElevate (/workspace/index.js:261:9) when uploaded and triggered by 'Test Function' from console.

I can't see why the res object would have lost its functions?

exports.pullElevate = async function (req, res) {

    // get CSV from Elevate API -> Write it to bucket -> copy from bucket to table...
    try {
        const payload = await getCSV()
        const filename = await putInBucket(payload.data)
        await writeCSVtoTable(filename)
        await mergeToMainTable()
    } catch (err) {
        console.error(err);
        res.status(500).send(err)
        return Promise.reject(err)
    }

    res.send("OK")
    return
}

Upvotes: 0

Views: 628

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 75790

I understand (and I guess by your description) that you bind your Cloud Functions to a PubSub topic to pull the message. Like this, you didn't have created a Http Function, but a background function. And the signature isn't the same

The second argument is a context object, and obviously, it hasn't a send function. Change your deployment. Deploy an HTTP function and create a PubSub push subscription to your Cloud Functions if you want (need?) to send a response to a received message (from PubSub or elsewhere!!)

Upvotes: 1

Related Questions