1.0.1 • Published 6 years ago

async-nocatch v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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)
}