@replygirl/tc
v4.0.2
Published
destructurable, async-friendly `try...catch` wrapper function with support for error side effects and fallback values
Downloads
81
Maintainers
Readme
tc
destructurable, async-friendly try...catch
wrapper function with support for error side effects and fallback values
Installation & usage
See the docs for full details.
import tc from '@replygirl/tc'
// get the return value and error of a try callback
const [x, e] = tc(() => { /* ... */ })
// or put complex error handling in a catch callback
const [y] = await tc(doSomething, async e => {
await reportError(e)
return getFallbackValue(e)
})
// reuse your error handling by defining your own wrapper
const tce = (t, c) => tc(t, async e => {
await reportError(e)
return c(e)
})
const [z] = tce(doSomething, getFallbackValue)