Open felipeavl opened 4 years ago
Post the entire console log.
I just wrote a Stack Overflow question about this too: https://stackoverflow.com/questions/63084656/proper-express-error-handling-with-promises-and-avoiding-err-http-headers-sent.
I'll update that if I find any solution.
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
My code is exactly the same as the sreams.js in the repository. Any ideas of how to solve this ??