1
0
Fork 0
peertube/server/middlewares/async.ts

17 lines
560 B
TypeScript
Raw Normal View History

2017-10-25 05:55:06 -04:00
import { Request, Response, NextFunction } from 'express'
// Syntactic sugar to avoid try/catch in express controllers
// Thanks: https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016
function asyncMiddleware (fn: (req: Request, res: Response, next: NextFunction) => Promise<any>) {
return (req: Request, res: Response, next: NextFunction) => {
return Promise.resolve(fn(req, res, next))
.catch(next)
}
}
// ---------------------------------------------------------------------------
export {
asyncMiddleware
}