Skip to content

Instantly share code, notes, and snippets.

@mfix22
Created September 25, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfix22/8bf4b17b870048ee4e14b5f7ff26fa81 to your computer and use it in GitHub Desktop.
Save mfix22/8bf4b17b870048ee4e14b5f7ff26fa81 to your computer and use it in GitHub Desktop.
Protect a function from all errors. Returns a Promise
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