如何在node.js express中记录导致错误的url
当在如何在node.js express中记录导致错误的url,node.js,express,Node.js,Express,当在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 header
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呢?有一个简单的代码可以在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
});
您可能可以使用thanx@dc5,但当使用I need callnext()
时,无论在哪里我都会遇到错误,但错误总是在您不希望出现的地方跳出thanx@Ashwin,但我使用的和我的请求处理程序与您的示例不同:app.get('/user/:id?',function(req,res){console.log(req.route);})代码>。所以我不知道如何使用request.on