Back End Development and APIs Projects - Exercise Tracker - Seems to work fine but is still failing tests

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.

Your project link(s)

solution: boilerplate-project-exercisetracker - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 OPR/97.0.0.0

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

You’re getting errors in the server console like

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.

1 Like