Rishikant181 / Rettiwt-API

A CLI tool and an API for fetching data from Twitter for free!
https://rishikant181.github.io/Rettiwt-API/
MIT License
306 stars 31 forks source link

TypeError: Cannot read properties of undefined (reading '__typename') while getting tweet.favoriters #379

Closed SomveerKr closed 9 months ago

SomveerKr commented 9 months ago

I was getting below errors while trying to get all the favoriters(all users who have liked partcular tweet) of a tweet using rettiwt.tweet.favoriters(tweetId)

TypeError: Cannot read properties of undefined (reading '__typename') at new CursoredData (F:\twitter-api\retwitt\node_modules\rettiwt-api\dist\models\CursoredData.js:45:22) at FetcherService.extractData (F:\twitter-api\retwitt\node_modules\rettiwt-api\dist\services\FetcherService.js:161:16) at TweetService. (F:\twitter-api\retwitt\node_modules\rettiwt-api\dist\services\FetcherService.js:181:37) at step (F:\twitter-api\retwitt\node_modules\rettiwt-api\dist\services\FetcherService.js:33:23) at Object.next (F:\twitter-api\retwitt\node_modules\rettiwt-api\dist\services\FetcherService.js:14:53) at fulfilled (F:\twitter-api\retwitt\node_modules\rettiwt-api\dist\services\FetcherService.js:5:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Rishikant181 commented 9 months ago

Does this happen after some iterations or on the first iteration while fetching all favoriters?

Rishikant181 commented 9 months ago

Okay, I was able to reproduce the issue, working on a fix now.

Rishikant181 commented 9 months ago

@SomveerKr The problem that is happening is that the while processing the list of favoriters, one of the favoriter's Twitter account has been suspended/deleted. So it's details are empty and as such, the processing fails.

I'll make sure to prevent such an error crashing the package in a minor patch.

Rishikant181 commented 9 months ago

@SomveerKr Please update to v2.2.2

SomveerKr commented 9 months ago

Thanks, for so much speedy fix, I have already fixed this error week ago(while working on client's project), just wanted to tell you that this issue exists so that it get fixed before anyone else uses it.

Here is what I implemented to fix this issue: I changed the code in CursoredData.js to this for (var _i = 0, list_1 = list; _i < list_1.length; _i++) { var item = list_1[_i]; // If the item is a valid raw tweet if (typeof item !== "undefined" && item.typename == 'Tweet' && item.rest_id) { this.list.push(new Tweet_1.Tweet(item)); } // If the item is a valid raw user else if (typeof item !== "undefined" && item.typename == 'User' && item.rest_id && item.id) { this.list.push(new User_1.User(item)); } }

from this for (var _i = 0, list_1 = list; _i < list_1.length; _i++) { var item = list_1[_i]; // If the item is a valid raw tweet if (item.typename == 'Tweet' && item.rest_id) { this.list.push(new Tweet_1.Tweet(item)); } // If the item is a valid raw user else if (item.typename == 'User' && item.rest_id && item.id) { this.list.push(new User_1.User(item)); } }

Rishikant181 commented 9 months ago

Thanks for the feedback!

What I did to fix it is this:

// Deserializing the input raw data and storing it in the list for (const item of list) { // If the item is a valid raw tweet if (item && item.__typename == 'Tweet' && item.rest_id) { this.list.push(new Tweet(item as IRawTweet) as T); } // If the item is a valid raw user else if (item && item.__typename == 'User' && item.rest_id && (item as IRawUser).id) { this.list.push(new User(item as IRawUser) as T); } }

If only I weren't lazy regarding edge cases :P