小编ABS*_*ACT的帖子

TypeError:res.status 不是错误处理中间件中的函数

我只是想添加一个最小的中间件来处理我的 Express TypeScript 项目中的错误。
我使用庆祝活动中的错误方法来让它处理庆祝/joi 错误,并希望添加另一个方法来处理其他错误。
这是我的代码:

app.use(errors()); // celebration error handling
app.use((err: any, req: Request, res: Response) => res.status(300).json(err.message));
Run Code Online (Sandbox Code Playgroud)

我为了测试它,尝试将 GET 发送到不存在的端点,但我不断收到此错误:TypeError: res.status is not a function

我应该怎么做才能像我想要的那样使用 Request ?

api node.js express typescript

3
推荐指数
1
解决办法
6063
查看次数

标签 统计

api ×1

express ×1

node.js ×1

typescript ×1