Created
September 25, 2017 17:07
-
-
Save mfix22/8bf4b17b870048ee4e14b5f7ff26fa81 to your computer and use it in GitHub Desktop.
Protect a function from all errors. Returns a Promise
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
const catchErrors = (fn, handleErrors) => { | |
try { | |
return Promise.resolve(fn()).catch(handleErrors) | |
} catch (e) { | |
handleErrors(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment