Wrapper for express routers or app for transparent work with async controllers and error handling.
Usage:
const express = const toAsyncRouter = const router = router
and so on.
Thrown errors can be catched with standard express middleware.
By default decorator works for methods: get
, post
, put
, delete
. If you want extend or shrink this list, use toAsyncRouter.setMethods()
before toAsyncRouter()
call:
const express = const toAsyncRouter = toAsyncRouter const router = routerall'/some-route' someAsyncController
It is also possible to get a list of methods that will be decorated:
console