Skip to content

Instantly share code, notes, and snippets.

@odykyi
Created August 9, 2018 08:24
Show Gist options
  • Save odykyi/010d4ce27ffd51c09157de4caba6cacb to your computer and use it in GitHub Desktop.
Save odykyi/010d4ce27ffd51c09157de4caba6cacb to your computer and use it in GitHub Desktop.
no try/catch in async/await ( nodejs node node.js js error handling arrow function)
module.exports = function of(promise) {
return Promise.resolve(promise)
.then((ret) => ret)
.catch((err) => {
if (!err) {
let error = new Error("Rejection with empty value");
error.originalValue = err;
err = error;
}
return [undefined, err];
});
}
const of = require('./await-of');
(async () => {
const fooFunction = async () => {
console.log('log', 1111);
return 2222;
}
const res = await of(fooFunction());
console.log('res', res);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment