我在try / catch块中遇到问题,这里是代码:
catch((err) => {
winston.error(new Date() +' : '+req.originalUrl +' : '+`${id}`+' : '+err);
res.status(500);
})
当请求失败时,调用winston的catch块在控制台中打印错误,但是请求没有停止的问题,我试图发送500代码它不起作用(这里是postman的截图,当catch块被调用时)。
我现在的问题是,如何发送500代码错误,并同时停止请求过程。
试试吧
res.sendStatus(500);
代替
res.status(500);
后者仅设置响应的statusCode
属性,但它不发送任何内容