Using promises to check a database for the User. Looking for a way I can construct a .then
that carries on even if the promise is rejected. Can i handle a rejected promise with .then
? Essentially combine my existing .then
and .catch
getUserData(UserId)
.then((data) => {
if (data.Item.UserId == UserId ) {
console.log("Welcome Back");
var checkFirst = "returning";
}
})
.catch((err) => {
console.log(err);
console.log("It's a stranger");
var checkFirst = "firstSession";
});
Edit - getUserData Function:
function getUserData(UserId) {
const docClient = new AWS.DynamoDB.DocumentClient();
const params = {
TableName: "XXXXXXXXXXX",
Key: {
"UserId": UserId,
}
};
return docClient.get(params).promise();
}