Node.js在结束错误后写入

时间:2015-08-07 08:46:56

标签: javascript node.js

我有以下代码完全在节点v0.10.28中工作。

app.use(function (req, res, next) {
        if (req.path === "/" || req.path === "/index.html") {
            var token = req.cookies && req.cookies.token ? req.cookies.token : undefined;
            if (token) {
                next();
            } else {
                console.log("Request url is....................." + req.url);
                console.log("time while redirecting to login...." + new Date());
                console.log("userAgents........" + req.headers['user-agent']);
                try { 
                    res.redirect('/login');
                } catch (error) {
                    console.log("error....." + error.message);
                }
            }
        } else {
            next();
        }
    });

但是在切换到节点v0.12.7之后,这是错误的。

Error: write after end 
at ServerResponse.OutgoingMessage.write (_http_outgoing.js:413:15) 
at ServerResponse.res.write (/node_modules/compression/index.js:87:17) 
at ServerResponse.res.end (/node_modules/compression/index.js:104:14) 
at ServerResponse.redirect (/node_modules/express/lib/response.js:846:8) 
at Http.js:11:21 at Layer.handle [as handle_request]

此错误连续发生3次,然后每小时后重复一次。 这是我的一些游戏机。

Request url is...................../
Time while redirecting to login....Thu Aug 06 2015 15:58:18 GMT+0000 (UTC)
UserAgents........Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36
Uncaught Err>>>>>>Error: write after end

Request url is...................../
Time while redirecting to login....Thu Aug 06 2015 15:58:18 GMT+0000 (UTC)
UserAgents........Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36
Uncaught Err>>>>>>Error: write after end

Request url is...................../
Time while redirecting to login....Thu Aug 06 2015 15:58:31 GMT+0000 (UTC)
UserAgents........Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36
Uncaught Err>>>>>>Error: write after end

此错误未在catch块中捕获并成为未被捕获的错误。

我将非常感谢有关如何解决此问题的任何提示。

0 个答案:

没有答案
相关问题