1.0.1 • Published 7 years ago
async-nocatch v1.0.1
async-nocatch
Get rid of try/catch wrappers for your async/await functions.
Why?
- Unnecessary nesting
- Failure is not always an error but
try/catchmeans handling error - You should always
catch
Installation
npm i async-nocatch # or yarn add async-nocatchimport 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)
}