I have this code snippet from the twit module of nodejs:
function tweets() {
T.get('search/tweets', { q: input, since:'2013-11-11', count: 3 }, function(err, data, response) {
if (data) {
sendMain(data.statuses[0].text);
}
else if (err) {
sendMain(err);
}
})
}
and everything works fine except the error handling, for example, if I search for food, a tweet will pop up, but if I search for ljfhlsjkdfhsldf if comes with the error of:
sendMain(data.statuses[0].text);
^
TypeError: Cannot read property 'text' of undefined
at c:\Users\karim_000\dropbox\main\bot2.js:235:44
at responseHandler (c:\Users\karim_000\dropbox\main\node_modules\twit\lib\oa
request.js:375:12)
at passBackControl (c:\Users\karim_000\dropbox\main\node_modules\twit\node_m
odules\oauth\lib\oauth.js:367:11)
at IncomingMessage.<anonymous> (c:\Users\karim_000\dropbox\main\node_modules
\twit\node_modules\oauth\lib\oauth.js:386:9)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:943:16
at process._tickCallback (node.js:419:13)
Program node bot2 exited with code 8
Why isnt my error handling working? any help? Thanks.
data.statusesexists, but it's an empty array.if (!data.statuses.length) error()