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
- Host: GitHub
- URL: https://github.com/zhigalov/catch-error-async
- Owner: Zhigalov
- Created: 2017-10-11T09:34:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-11T11:14:22.000Z (over 7 years ago)
- Last Synced: 2025-03-28T02:02:32.199Z (2 months ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```