error-first
TypeScript icon, indicating that this package has built-in type declarations

0.9.4 • Public • Published

error-first

Convert async/await try/catch to [error, result]

tl;dr

import errorFirst from 'error-first'
 
const [error, result] = await errorFirst(doSomething)

Details

Given an async operation

const addAsync = async (a, b) => {
    if (a == null || b == null) {
        throw 'Argument Error'
    }
 
    return a + b
}

With error-first

import errorFirst from 'error-first'
// const errorFirst = require('error-first').default
 
const [error, result] = await errorFirst(addAsync(1, 2)) // [undefined, 3]

With standard async/await

let result = null
 
try {
    result = await addAsync(1, 2)
} catch(error) {
    // Do something with error
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.9.4
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.9.4
    0
  • 0.9.3
    1
  • 0.9.2
    1
  • 0.9.0
    1

Package Sidebar

Install

npm i error-first

Weekly Downloads

3

Version

0.9.4

License

MIT

Last publish

Collaborators

  • dalejefferson