1.0.16 • Published 11 months ago

await-protect v1.0.16

Weekly downloads
3
License
MIT
Repository
github
Last release
11 months ago

await-protect

Wraps promises to destructure values easily without having to nest with try catch. Gives easier error typing as well.

Usage

import protect from "await-protect"

async function do() {
    const json = { "msg": "Hello" }

    const [res, err] = await protect(
      axios.post(`${config.url}`, qs.stringify({
        data: new Buffer(JSON.stringify(a)).toString("base64")
      })))

    if (err) {
        console.log(err)
        return
    }

    console.log(res.data)
}

Instead of this:

async function do() {
    const json = { "msg": "Hello" }

    try {
        const res: AxiosResponse = await axios.post(`${config.url}`, qs.stringify({
            data: new Buffer(JSON.stringify(a)).toString("base64")
        }))

        console.log(res.data)
    } catch (err) {
        console.log(err)
    }
}
1.0.16

11 months ago

1.0.15

2 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

5 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago