gpt4 book ai didi

javascript - 范围错误: Invalid status code: 0 in Express App - Session issue?

转载 作者:行者123 更新时间:2023-11-28 05:37:49 25 4
gpt4 key购买 nike

我在 Express 应用程序上遇到此随机错误:

_http_server.js:192
throw new RangeError(`Invalid status code: ${statusCode}`);
^

RangeError: Invalid status code: 0
at ServerResponse.writeHead (_http_server.js:192:11)
at ServerResponse.writeHead (/project-folder/node_modules/express-session/node_modules/on-headers/index.js:55:19)
at ServerResponse._implicitHeader (_http_server.js:157:8)
at ServerResponse.OutgoingMessage.end (_http_outgoing.js:573:10)
at writeend (/project-folder/node_modules/express-session/index.js:257:22)
at Immediate.onsave [as _onImmediate] (/project-folder/node_modules/express-session/index.js:325:11)
at processImmediate [as _immediateCallback] (timers.js:383:17)

我尝试通过执行类似的操作来修复它,但没有成功:

app.use(function(req, res, next) {
req.on("end", function() {
if (res.statusCode < 100 && res.statusCode >= 600) {
res.status(500);
}
});
next();
});

我不知道在哪里找到错误,或者至少放置一个 try catch,错误是随机的,并且跟踪不是很明确。

欢迎任何帮助,谢谢!

最佳答案

在我在本地主机上托管用于开发和测试的两个项目之间切换时,我看到了类似的错误。在浏览器中手动删除 localhost 的 cookie 解决了我的问题。我用你的函数来找出答案。打印出所有请求的 req.headers 让我意识到,当在本地主机上的不同项目之间切换时,cookie 仍然存在。

关于javascript - 范围错误: Invalid status code: 0 in Express App - Session issue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39210247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com