我有一条路由,其中包含各种中间件。某些中间件可能会出错,但是静默的,不会阻止执行。这些错误由myAppErrorMiddleware error middleware
使用next(error)
处理。
但是一旦错误由myAppErrorMiddleware
处理后,应用程序应继续执行路径(middleware2
)中的下一个逻辑功能
我尝试在错误中间件中添加next('route')
,但是我没有加入middleware2
...
在指控middleware2
之后,有没有办法对myAppErrorMiddleware
进行执行?
app.get('/', middleware1, middleware2)
middleware1 = (
req: Request,
res: Response,
next: NextFunction,
) => {
// ... throws and error
next(error); // goes to error middleware
}
const myAppErrorMiddleware: ErrorRequestHandler = (
err: Error | AxiosError | any,
req: Request,
res: Response,
next: NextFunction,
) => {
// Handdles the error but does not end the execution of events,
// I want it to carry on to 'middleware2'
next("route");
};
app.use(myAppErrorMiddleware);