Brad Thomas
Brad Thomas

Reputation: 185

HTTP Response Error - Firebase + Node JS 16

I've reduced my code to the bare minimum to troubleshoot why I receive a response error when I put a HTTP request in.

I first receive a status 200 message upon deploying the function but when I access the URL to perform the HTTP request, I receive this response error and never receive "done".

Here is the code:

const functions = require("firebase-functions");
const axios = require("axios");
const csv = require("csv-parser"); // not used in minimum reproducible 
const fs = require("fs"); // not used in minimum reproducible 

const windArr = []; // not used in minimum reproducible 

/* eslint require-jsdoc: 1 */
/* eslint no-unused-vars: 1 */

exports.HTTPTest = functions.https.onRequest((req, res) => {
  res.send("Scraping the web...");
  console.log("done");
  // getWindForecast();
});

response error

Upvotes: 0

Views: 227

Answers (2)

Robert Sandberg
Robert Sandberg

Reputation: 8635

It seems like this is a current known issue when a function returns anything but a 200. Even 201 and 204 give response error in the logs. It seems to only affect the logs and not the actual response. I've verified this in my setup.

In this SO question:

GCP logs show function "Function execution took xxx ms. Finished with status: response error" whenever my header status code is not 200

The following comment was written:

The product team is aware of this issue and they have updated today that the change is reverted back, you can expect the previous behavior to be resumed shortly. Let me know if you face any errors after a day or two. – Priyashree Bhadra Apr 19 at 11:02

Upvotes: 0

Renaud Tarnec
Renaud Tarnec

Reputation: 83191

It is normal that you don't see the output of console.log("done"); in the Cloud Functions console: as soon as you call res.send() you actually terminate your HTTPS Cloud Function as explained in the doc.

To verify that your Cloud Function works, call it from a client (or via curl) and verify that the HTTP response contains what you have passed to the send() method.


PS: If you encounter CORS errors, see this part of the doc.

Upvotes: 2

Related Questions