There was an application error recently when during the dBWrapper.queryUserFriends
call... I tried to hit a table that doesn't exist in the database. That is all resolved and made sense but I also get the following warning that I can't figure out why. I tried to add a catch to all the asynchronous calls as well but that didn't help
Getting the following warning from nodejs:
(node:7741) UnhandledPromiseRejectionWarning: Unhandled promise rejection (node:7741) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. */
router.get("/getUserDetails", function(req, res) {
doesUserExist(User)
.then(id => getUserData(id))
.then(userData => res.json(userData))
.catch(error => res.json({
'error': error
}));
});
function getUserData(id) {
return new Promise((resolve, reject) => {
dBWrapper.queryUserDetails(id)
.then(async function(data) {
for (x in data) {
await dBWrapper.queryUserFriends(data)
.then(function(result) {
// <------ where the error happens
})
}
resolve(data)
});
});
}
function queryUserDetails(id) {
let query = 'SELECT * from User where User.id =' + id;
return processQuery(query);
}
function queryUserFriends(id) {
let query = 'SELECT * from Friends where User.id =' + id;
return processQuery(query);
}
function processQuery(query) {
return new Promise(function(resolve, reject) {
let connection;
db
.getConnection()
.then(function(c) {
connection = c;
return connection.execute(query);
})
.then(
function(result) {
resolve(result.rows);
},
function(err) {
reject(err);
}
)
.then(function() {
if (connection) {
return connection.close();
}
})
});
}