well I'm immigrating my code to ES7, syntaxes like arrow function and async/await. The problem is I don't get how to use call back when If I try to save variable and callback when error occurs at the same time using async/await
.
Here's the code. I want to save result from request to redditJSON variable using await with rp but I want to add callback for error handling too. but I have no idea how to implement this.
rp
is request-promise npm module.
let redditJSON = await rp(optForReddit)
EDDIT 1
let redditJSON;
try { redditJSON = await rp(optForReddit) }
catch(err) { console.error(err) }
via yaomohi
No comments:
Post a Comment