Created
July 5, 2018 12:42
-
-
Save devCola/d699827bdb258dcec9ec7b7341fe95fa to your computer and use it in GitHub Desktop.
wrapper for common error handling
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
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