Created
April 3, 2020 18:09
-
-
Save meehanman/08a18ffe9333e82fee33bed3704ba56f to your computer and use it in GitHub Desktop.
NodeJS Examples of Promises for accessing AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return await docClient.query(findGameParams).promise().then((games) => { | |
if (games.Count == 1) { | |
return Promise.resolve(games.Items[0]) | |
} else { | |
return Promise.reject("Could not find that game") | |
} | |
}); | |
return await new Promise((resolve, reject) => { | |
docClient.query(findGameParams, function (err, games) { | |
if (err) { | |
return reject(err); | |
} else { | |
if (games.Count == 1) { | |
return resolve(games.Items[0]); | |
} else { | |
return Promise.reject("Could not find that game") | |
} | |
} | |
}) | |
}); | |
// --------------------------------------- | |
await gameController.gameInfo(req.params.gameid) | |
res.status(200).json(gameInfo); | |
// ...and surround in try{catch{ | |
//---- or | |
gameController.gameInfo(req.params.gameid).then((data) => { | |
res.status(200).json(data); | |
}).catch((error) => { | |
res.status(400).json(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment