Open abdhalees opened 7 years ago
Agreed, the if (data)
condition may be dangerous, because it is executed in the same loop tick as let data = ''
. To me this would suggest that if (data)
can never be true, because the req.on('data',...)
callback doesn't have a chance to execute (remember the event-loop and its relation to the call stack!).
Best instead to use the event listeners req.on('data', ...)
, req.on('end', ...)
and req.on('error', ...)
.
The same issue exists in the login handler: https://github.com/FACG2/Nerd-s-flashCards/blob/8febfae4e01409f49ed536ba5b76678501321193/src/handlers.js#L103
I don't think you need this condition because if there isn't data or it's corrupted it will be handled in line 83.
Also if the error is handling wrong data you could use status code 406 for not acceptable or 500 for internal server error. https://github.com/FACG2/Nerd-s-flashCards/blob/8febfae4e01409f49ed536ba5b76678501321193/src/handlers.js#L92