【发布时间】:2021-11-01 22:22:11
【问题描述】:
app.use("/login", login);
app.use("*", (err: any, req: Request, res: Response, next: NextFunction) => {
console.log('errrorrrr')
res.send('ERRORRRRR4040404040404 ******')
});
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
console.log('errrorrrr')
res.send('ERRORRRRR4040404040404')
});
app.listen(config.port, () => {
console.log(`Running at port ${config.port}`);
});
我在路由之后设置了这两个错误处理程序。我没有设置res.send(),而是在我的浏览器上得到Cannot GET /whynowork,而我的节点上没有console.log。
如何正确设置404 Error?我试过只放一个,但它仍然返回 Cannot GET /whynowork 并且不通过错误处理程序。
【问题讨论】: