Wraps async/await Express middlewares. Catches error and passes it to next.
Avoid wrinting try/catch in your middlewares.
DRY when catching errors from asyn/await Express middlewares.
This module exposes a wrapper for param middleware as well, which is using a different signature (req, res, next, value)
.
Where function
returns a promise and accepts req
, res
, next
arguments.
Where function
returns a promise and accepts req
, res
, next
and value
arguments.
import { middleware, paramMiddleware } from "asyncable"
// const { middleware, paramMiddleware } = require('asyncable')
// ...
router.param('userId', paramMiddleware(model.findObject.bind(model)))
router.route('/')
.get(
// ACL middleware or whatever before for instance...
middleware(userController.list.bind(userController))
)
.post(
// ACL middleware or whatever before for instance...
middleware(userController.add.bind(userController))
)