Need to terminate POST function and send Error: something as response, without terminating program.
Sample for-loop:
for (let i = 0; i < req.body.listoftouristsbyid.length; i++) {
client.query("SELECT tourists.id FROM tourists WHERE tourists.id = " + req.body.listoftouristsbyid[i], function(err, result) {
done();
if (result.rows.length === 0) {
console.log("Tourist " + req.body.listoftouristsbyid[i] + " you want to add does not exist");
res.status(500);
return res.render("Bad listoftoutistbyid request, student with id " + i + " does not exist");
}
})
}
What should I write in place of return res.render, so POST won't work, function will terminate with error code in response, but without crashing program so I can send more requests later ?
OR...try ... catchstatement.