async-nocatch

1.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i async-nocatch

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

1.34 kB

Total Files

4

Last publish

Collaborators

  • kelin2025