Skip to content

Instantly share code, notes, and snippets.

@devCola
Created July 5, 2018 12:42
Show Gist options
  • Save devCola/d699827bdb258dcec9ec7b7341fe95fa to your computer and use it in GitHub Desktop.
Save devCola/d699827bdb258dcec9ec7b7341fe95fa to your computer and use it in GitHub Desktop.
wrapper for common error handling
async function withErrorHandler(
run: () => Promise<HTTPResponseType>,
options?: {
},
) {
try {
return run();
} catch (e) {
// handle error here.
// Note: use options & try to handle 100% of all the errors here...
}
}
const userList = withErrorHandler( () => axios.get('/api/userlist'), { ... });
// note: with scala/kotlin, you probably can get away with:
const userList = withErrorHandler{ axios.get('/api/userlist') }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment