When MySQL returns an error / exception, my nodejs server crashes.
Here is the code from my backend. I used if else in the query function, then I get the response but my server crashes. With try and catch it still crashes and I don't get any response back.
Rezervacija.create = function (newEmp, result) {
try{
konekcija.query("INSERT INTO rezervacija set ?", newEmp, function (err, res) {
console.log(res.insertId);
result(null, res.insertId);
});
}
catch(err){
result(err, null);
console.log("Error",err);
}
};
I tried, try and catch, but it doesn't seem to work, maybe im using it wrong? I'm really new to JS and still learning.
The only solution I see is to catch the error so it doesn't crash the server.
Thanks in advance.