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

https://github.com/zhigalov/catch-error-async

Catching errors с by async function
https://github.com/zhigalov/catch-error-async

Last synced: 2 months ago
JSON representation

Catching errors с by async function

Awesome Lists containing this project

README

        

# Catching errors throwed by async function

### Example
```js
const catchErrorAsync = require('catch-error-async');

// throw error with `message` and `code` from arguments
const cb = async (message, code) => {
await new Promise((resolve, reject) => {
setTimeout(() => reject({ message, code }), 0);
});
};

const error = await catchErrorAsync(cb, 'Mu-ha-ha!', 400);

console.log(error.message); // 'Mu-ha-ha!'
console.log(error.code); // 400
```