0

node.js express站点上发生错误时,其日志文件不会显示发生错误的 url。它显示了先前请求的 url。但是要调试错误,我需要知道导致错误的 url。

GET /some/local/url?page=2 200 339ms - 68b  # previus request

http.js:704                                 # error request without url
    throw new Error('Can\'t set headers after they are sent.');
          ^
Error: Can't set headers after they are sent.
  at ServerResponse.OutgoingMessage.setHeader (http.js:704:11)

永远使用和nginx. 那么如何让它显示导致日志文件错误的url呢?

4

1 回答 1

0

当 url 出错时,有一个简单的代码可以捕获错误:

var http = require("http");

var options = {
    host : "www.abc.com/get/something"
};

var request = http.request(options, function(req) {
    // DO WITH REQUEST
});
request.on('error', function(err) {
     console.log(err.domain); // domain url
     console.log(request.url); // URL of req made 
    // DO SOMETHING WITH ERROR
});
于 2013-08-30T06:14:27.007 回答