Skip to content

myrotvorets/express-async-middleware-wrapper

Repository files navigation

express-async-middleware-wrapper

Quality Gate Status Build and Test

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.

About

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

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •