I am purposefully causing the connection.execute
aspect of this promise to fail. When it does fail I get a 'Error Occured' in the console followed by an uncaught exception, the error I am producing, and then Node completely shutting down.
async function procExecute(query, binds, clientdetails = [], procdetails) {
return new Promise((resolve, reject) => {
// Acquire connection from pool
myPool.acquire().then(connection => {
// Execute the query
connection.execute({
sqlText: query,
binds: binds,
parameters: { MULTI_STATEMENT_COUNT: procdetails.statementcount },
complete: (err, stmt, rows) => {
console.log(`Conn: ${connection.getId()} fetched ${rows && rows.length} rows`);
// Return result
console.log(JSON.stringify(rows))
if (err) {
console.log('Error Occurred: ' + err)
// Return Error
resolve([{
"ERROR_CODE": Number(err.data.errorCode),
"ERROR_MSG": err.message
}])
// reject(new Error(err.message))
} else {
resolve(
[{
"ERROR_CODE": rows[0].P_ERROR_CODE,
"ERROR_MSG": rows[0].P_MSG
}]
);
}
// Return connection back to pool
myPool.release(connection);
}
});
}).catch(
console.log('Error Occured'),
(err) => {
reject([{
"ERROR_CODE": Number(9999),
"ERROR_MSG": err
}])
}
)
});
}
module.exports.procExecute = procExecute;