Created
January 15, 2018 18:47
-
-
Save zashishz/16d6cee57725ad6d3d0daadd429e0425 to your computer and use it in GitHub Desktop.
Centralised Error handler for async await
This file contains hidden or 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
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