gpt4 book ai didi

javascript - socket.io 错误 - 'Uncaught, unspecified "错误“事件。”

转载 作者:行者123 更新时间:2023-12-02 18:38:42 25 4
gpt4 key购买 nike

我有一个错误,但我不确定它的含义或如何调试它。错误如下:

events.js:74
throw TypeError('Uncaught, unspecified "error" event.');
^
TypeError: Uncaught, unspecified "error" event.
at TypeError (<anonymous>)
at EventEmitter.emit (events.js:74:15)
at EventEmitter.receive (/home/andy/dev/node/tweetmap/node_modules/ntwitter/lib/parser.js:41:14)
at IncomingMessage.<anonymous> (/home/andy/dev/node/tweetmap/node_modules/ntwitter/lib/twitter.js:266:14)
at IncomingMessage.EventEmitter.emit (events.js:95:17)
at IncomingMessage.<anonymous> (_stream_readable.js:736:14)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)

我的代码如下:

twit.stream('statuses/filter', { locations: locs, track: tracks }, function(stream) {
stream.on('data', function (data) {
var geo=false,latitude,longitude;

if(data.geo!=null){
geo = true;
latitude = data.geo.coordinates[0];
longitude = data.geo.coordinates[1];

var sentiment;
sentiment(data.text, function (err, result) {
sentiment = result.score;
io.sockets.volatile.emit('tweets', {
user: data.user.screen_name,
text: data.text,
geo : geo,
latitude: latitude,
longitude: longitude,
sentiment: sentiment
});
});
}
});
});

在添加情感函数之前,我的代码工作得很好,所以我认为这与调用的异步性质有关。有人可以帮我吗?

最佳答案

您正在尝试调用undefined

var sentiment;
console.log(typeof sentiment === 'undefined') // true
sentiment(data.text, function (err, result) {

尝试这样的事情:

var _sentiment;
sentiment(data.text, function (err, result) {
_sentiment = result.score;
io.sockets.volatile.emit('tweets', {
user: data.user.screen_name,
text: data.text,
geo : geo,
latitude: latitude,
longitude: longitude,
sentiment: _sentiment
});
});
}

关于javascript - socket.io 错误 - 'Uncaught, unspecified "错误“事件。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17045519/

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