Tell us what’s happening:
I seem to have finished the project but it is still failing tests and I can’t seem to figure out why. The tests failing are 8, 10, and everything on.
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:393:5)
at ServerResponse.setHeader (node:_http_outgoing:644:11)
at ServerResponse.header (/home/runner/boilerplate-project-exercisetracker-4/node_modules/express/lib/response.js:771:10)
at ServerResponse.send (/home/runner/boilerplate-project-exercisetracker-4/node_modules/express/lib/response.js:170:12)
at ServerResponse.json (/home/runner/boilerplate-project-exercisetracker-4/node_modules/express/lib/response.js:267:15)
at /home/runner/boilerplate-project-exercisetracker-4/index.js:103:11
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}
that you need to fix. These are caused by sending multiple responses. The best fix is to return responses like
return res.json({...});
so that no further responses are sent. Once you fix that, then you need to log your route inputs and responses and run the tests, producing
POST exercise
req.body: {"description":"test","duration":"60","date":"1990-01-01"}
req.params: {"id":"6438806c84c439aaa016a623"}
req.query: {}
{ error: 'error: not a valid id' }
for all tests which means your condition testing for valid IDs is always evaluating as bad IDs.
No other tests will pass without being able to successfully post exercise records.