Skip to content

Instantly share code, notes, and snippets.

@jagsbyteinception
Created May 21, 2020 21:21
Show Gist options
  • Save jagsbyteinception/a1fffb31e95a35a3f97688ced7538515 to your computer and use it in GitHub Desktop.
Save jagsbyteinception/a1fffb31e95a35a3f97688ced7538515 to your computer and use it in GitHub Desktop.
nodejs - non promise function to promise (support await)
async function asyncGetUserInfo(req) {
return new Promise((resolve) => {
if(!req.cookies.session){
return resolve(null);
}
var data = {'sessionToken': req.cookies.session};
hubsoft.getUserInfo(data, function (err, result) {
utils.cleanupObject(result);
if (!!result && (!result.out.errors || !result.out.errors.ErrorDTO || !result.out.errors.ErrorDTO.length)) {
resolve(result.out);
}
else{
winston.info('reject asyncGetUserInfo: ' + JSON.stringify({result,err}));
resolve(null);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment