@myrotvorets/express-async-middleware-wrapper
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

express-async-middleware-wrapper

Quality Gate Status Build and Test CI codebeat badge

Wrapper for Express.js async middleware to handle rejected promises and synchronous exceptions.

This library is similar to 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)

Usage

import { Request, Response, Router } from 'express';
import wrapper from '@myrotvorets/express-async-middleware-wrapper';

async function handler(req: Request, res: Response): Promise<void> {
    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.

Package Sidebar

Install

npm i @myrotvorets/express-async-middleware-wrapper

Weekly Downloads

0

Version

2.2.0

License

MIT

Unpacked Size

6.44 kB

Total Files

6

Last publish

Collaborators

  • unsung-hero