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)
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));
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.