async-nocatch
v1.0.1
Published
No need to use try/catch to handle your async/await functions
Downloads
4
Readme
async-nocatch
Get rid of try/catch
wrappers for your async/await
functions.
Why?
- Unnecessary nesting
- Failure is not always an error but
try/catch
means handling error - You should always
catch
Installation
npm i async-nocatch # or yarn add async-nocatch
import nocatch from "async-nocatch"
// For example
const nocatchFetch = nocatch(fetch)
Before
try {
const result = await fetch('https://api.github.com/users')
console.log('Done', result)
} catch (error) {
console.log('Fail', error)
}
After
const { success, result } = await nocatchFetch('https://api.github.com/users')
if (success) {
console.log('Done', result)
} else {
console.log('Fail', result)
}