Created
May 21, 2020 21:21
-
-
Save jagsbyteinception/a1fffb31e95a35a3f97688ced7538515 to your computer and use it in GitHub Desktop.
nodejs - non promise function to promise (support await)
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
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