https://github.com/myrotvorets/express-async-middleware-wrapper
Wrapper for Express.js async middleware to handle rejected promises and synchronous exceptions
https://github.com/myrotvorets/express-async-middleware-wrapper
express-async-middleware express-middleware handle-rejected-promises
Last synced: 7 months ago
JSON representation
Wrapper for Express.js async middleware to handle rejected promises and synchronous exceptions
- Host: GitHub
- URL: https://github.com/myrotvorets/express-async-middleware-wrapper
- Owner: myrotvorets
- License: mit
- Created: 2020-06-10T06:41:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-12-16T03:24:41.000Z (7 months ago)
- Last Synced: 2024-12-16T20:36:06.212Z (7 months ago)
- Topics: express-async-middleware, express-middleware, handle-rejected-promises
- Language: TypeScript
- Homepage: https://myrotvorets.center/
- Size: 2.91 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-async-middleware-wrapper
[](https://sonarcloud.io/dashboard?id=myrotvorets_express-async-middleware-wrapper)
[](https://github.com/myrotvorets/express-async-middleware-wrapper/actions/workflows/build.yml)Wrapper for Express.js async middleware to handle rejected promises and synchronous exceptions.
This library is similar to [express-async-handler](https://www.npmjs.com/package/express-async-handler) but is written in TypeScript, and its typings handle more cases than those of `express-async-handler` (for example, it can deal with the changes introduced in [DefinitelyTyped/DefinitelyTyped#49677](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/49677))
# Usage
```typescript
import { Request, Response, Router } from 'express';
import wrapper from '@myrotvorets/express-async-middleware-wrapper';async function handler(req: Request, res: Response): Promise {
const someAsyncResult = await someAsyncAction();
res.json(someAsyncResult);
}const router = Router();
router.get('/some-path', wrapper(handler));
```# What it Does
It provides error handling for asynchronous middleware by catching rejected promises and synchronous exceptions from handler's code.
This wrapper simplfies development by eliminating the need to write boilerplate code for asynchronous handlers.