Skip to content

Cannot set headers after they are sent to the client #18

@felipeavl

Description

@felipeavl

I have a problem with some of the functions , specifically the ones that query the database for some validation and then updates the documents.

The exports.commentOnScream for example. If I run it with an inexistent screamId I get the 404 response, but the code continues to the function on the next 'then()' and tries to return a json with the comment ( If I console.log something before res.json(newComment); it get printed ).

So I get the following error:

(node:27910) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

 at ServerResponse.setHeader (_http_outgoing.js:485:11)
 at ServerResponse.header (/home//Desenvolvimento/socialape-functions/functions/node_modules/express/lib/response.js:771:10)
 at ServerResponse.send (/home//Desenvolvimento/socialape-functions/functions/node_modules/express/lib/response.js:170:12)
 at ServerResponse.json (/home//Desenvolvimento/socialape-functions/functions/node_modules/express/lib/response.js:267:15)
 at /home//Desenvolvimento/socialape-functions/functions/handlers/screams.js:95:23
 at processTicksAndRejections (internal/process/task_queues.js:94:5)

My code is exactly the same as the sreams.js in the repository. Any ideas of how to solve this ??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions