An open API service indexing awesome lists of open source software.

https://github.com/robertoachar/node-catch-errors

A high-order function to catch errors from promises.
https://github.com/robertoachar/node-catch-errors

async await catch error errors node promises

Last synced: 2 months ago
JSON representation

A high-order function to catch errors from promises.

Awesome Lists containing this project

README

        

# catch-errors

Generated by [OSS Project Generator](http://bit.ly/generator-oss-project).

[![NPM Version][npm-badge]][npm-url]
[![License][license-badge]][license-url]

> A high-order function to catch errors from promises.

## Installation

Install package

```bash
$ npm install --save catch-errors
```

## Usage

```js
const fetch = require('node-fetch');
const catchErrors = require('catch-errors');

async function load(username) {
const response = await fetch(`https://api.github.com/users/${username}`);
const user = await response.json();
console.log(user.name);
}

const wrappedLoad = catchErrors(load);

wrappedLoad('robertoachar');
```

## Development

- Cloning the repo

```bash
$ git clone https://github.com/robertoachar/node-catch-errors.git
```

- Installing dependencies

```bash
$ npm install
```

- Running scripts

| Action | Usage |
| ------------ | -------------- |
| Linting code | `npm run lint` |

# Author

[Roberto Achar](https://twitter.com/robertoachar)

# License

[MIT](https://github.com/robertoachar/node-catch-errors/blob/master/LICENSE)

[npm-badge]: https://img.shields.io/npm/v/catch-errors.svg
[npm-url]: https://www.npmjs.com/package/catch-errors
[license-badge]: https://img.shields.io/github/license/robertoachar/node-catch-errors.svg
[license-url]: https://opensource.org/licenses/MIT