在express中使用async/await来控制异步流程,为了防止异常写了很多try/catch,不知道express能否在入口文件中处理所有程序执行过程中抛出的异常。
已自行解决
function ar(cb: (req: express.Request, res: express.Response, next: Function) => any) { return function (req: express.Request, res: express.Response, next: Function) { cb(req, res, next).catch((error: any) => { next(error); }); } } router.get('/', ar(async function(req, res){ // 哈哈 }));
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
已自行解决
本楼正解