Nerds-Who-Code / Mental-Health-Tracker

mental-health-tracker.vercel.app
MIT License
6 stars 6 forks source link

Registering an account that already exists crashes the server #51

Closed steph-koopmanschap closed 2 years ago

steph-koopmanschap commented 2 years ago

Describe the bug When a user creates an account that is already existing the server shuts down in an error:

node:internal/errors:477
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:388:5)
    at ServerResponse.setHeader (node:_http_outgoing:603:11)
    at ServerResponse.header (/home/notaspoon/programming/websites/collab/Mental-Health-Tracker/server/node_modules/express/lib/response.js:794:10)
    at ServerResponse.send (/home/notaspoon/programming/websites/collab/Mental-Health-Tracker/server/node_modules/express/lib/response.js:174:12)
    at /home/notaspoon/programming/websites/collab/Mental-Health-Tracker/server/APIrouter.js:175:25
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

To Reproduce Steps to reproduce the behavior:

  1. Go to create account
  2. Enter the exact same details of an account that already exists
  3. It says "Account successfully registered"
  4. The server shuts down. See error. The client gives no errors.

Expected behavior Registering a user that already exists should return a normal error that does not crash the server.