ERR_HTTP_HEADERS_SENT - Firebase / Node js / Express

164 views
Skip to first unread message

Tomy Tubert

unread,
May 10, 2022, 10:12:43 AM5/10/22
to Firebase Google Group
Hi!
I'm developing my backend with Express and Firebase.
I'm having problems with this error:

_http_outgoing.js:558
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:558:11)
    at ServerResponse.header (/Users/tomytubertgonzalez/Desktop/OMD/omd_api/node_modules/express/lib/response.js:794:10)
    at ServerResponse.send (/Users/tomytubertgonzalez/Desktop/OMD/omd_api/node_modules/express/lib/response.js:174:12)
    at ServerResponse.json (/Users/tomytubertgonzalez/Desktop/OMD/omd_api/node_modules/express/lib/response.js:278:15)
    at /Users/tomytubertgonzalez/Desktop/OMD/omd_api/controllers/advert.controllers.js:26:25
    at DocumentWatch.onNext (/Users/tomytubertgonzalez/Desktop/OMD/omd_api/node_modules/@google-cloud/firestore/build/src/reference.js:429:21)
    at DocumentWatch.pushSnapshot (/Users/tomytubertgonzalez/Desktop/OMD/omd_api/node_modules/@google-cloud/firestore/build/src/watch.js:468:18)
    at DocumentWatch.onData (/Users/tomytubertgonzalez/Desktop/OMD/omd_api/node_modules/@google-cloud/firestore/build/src/watch.js:352:26)
    at PassThrough.<anonymous> (/Users/tomytubertgonzalez/Desktop/OMD/omd_api/node_modules/@google-cloud/firestore/build/src/watch.js:314:26)
    at PassThrough.emit (events.js:315:20) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

The function is:
exports.updateAdvert = async (req, res) => {
try{
const {id,advert} = req.body;
await db.collection("adverts").doc(id).update(advert);
return res.status(200).json({advert});
}catch(e){
return res.status(400).json({ message: `Llamada fallida: ${e}` });
}
};

It's weird because the .update() is executed but the backend brakes because that error.
Actually I try it without try catch but nothing changes.

Thanks!


Reply all
Reply to author
Forward
0 new messages