mern-starter
mern-starter copied to clipboard
Code execution continues when it should stop in POST action
Hello. If you try to post empty data via API, not React client application, the application will crash. The particular line in problem is in post.controller.js file, where you check if name, title or content are empty. The line:
res.status(403).end();
should abort execution. Possible solution could be:
return res.status(403).end();
but it raises eslint consistent-return warning.
The problem can be avoided by putting return on the next line:
res.status(403).end(); return;
And I am not sure whether 403 (unauthorized) is appropriate here, shouldn't be 400 when invalid data is sent?