所有的函数都在工作,但这个错误来了两个更放或删除函数是一次又一次地调用它的发生的时间
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:371:5)
at ServerResponse.setHeader (node:_http_outgoing:576:11)
at ServerResponse.header (C:\Users\ND\StudioProjects\pos\node_modules\express\lib\response.js:794:10)
at ServerResponse.send (C:\Users\ND\StudioProjects\pos\node_modules\express\lib\response.js:174:12)
at ServerResponse.json (C:\Users\ND\StudioProjects\pos\node_modules\express\lib\response.js:278:15)
at deleteAddItem (file:///C:/Users/ND/StudioProjects/pos/controller/bill/addItem.controller.js:41:21)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}
const deleteAddItem = async (req, res) => {
try {
const getItem = req.body;
const deleteItem = await AddItem.findOneAndDelete(getItem);
if (!deleteItem) res.status(203).json({ msg: "No bill available" });
return res.status(202).json({ msg: "Bill Deleted" });
} catch (error) {
console.error(error);
res.status(500).json({ msg: "Internal Server Error deleteAddItem", error });
}
};
路由器文件
billRouter.delete("/deleteAddItem", deleteAddItem);
我不知道这是怎么回事!
1条答案
按热度按时间sz81bmfz1#
在
if
配置中添加return
语句: