Skip to content

Instantly share code, notes, and snippets.

@zashishz
Created January 15, 2018 18:47
Show Gist options
  • Save zashishz/16d6cee57725ad6d3d0daadd429e0425 to your computer and use it in GitHub Desktop.
Save zashishz/16d6cee57725ad6d3d0daadd429e0425 to your computer and use it in GitHub Desktop.
Centralised Error handler for async await
function delay () {
return new Promise((res, rej) => {
setTimeout(() => {
rej(5);
}, 3000)
})
}
const hof = (func) => {
return func().catch((err) => {
console.log("ooops!", err);
});
}
const aha = async () => {
const val = await delay();
console.log('My value is ', val);
}
hof(aha);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment