I\'ve read several examples for using mysql in node.js and I have questions about the error handling.
Most examples do error handling like this (perhaps for brevity)
I guess this method is more approachable. In this case even if you fail to gain connection you throw an Internal Server Error status to client(helpful if you building a Rest Api Server) and in case there is a query error after releasing connection your sending the error. Please correct me if am wrong anywhere.
pool.getConnection(function(err, connection){
if(err){
console.log(err);
return res.status(500).json();
};
connection.query('SELECT * FROM TABLE', function(err,results,fields){
connection.release();
if(err){
console.log(err);
return (res.status(500).json());
};
res.status(201).send('OK');
});
});