PLhery / node-twitter-api-v2

Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
https://www.npmjs.com/package/twitter-api-v2
Apache License 2.0
1.28k stars 176 forks source link

[Question] What is the convention around handling TweetParseError errors? #536

Open jbyman opened 3 months ago

jbyman commented 3 months ago

Hello,

Thank you for this library! This has been great so far. I had a question I was hoping you'd be able to help with (apologies if I missed this in the docs or existing issues).

I'm using this library for some reasonably high throughput tweets, and occasionally we'll hit the tweet parse errors:

stream.on(ETwitterStreamEvent.TweetParseError, (err) => {
      Log('Error parsing tweet from stream', {
        msg: err.message,
        name: err.name,
      });
});

This is relatively seldom, only once in every few thousand tweets. However, I'm curious what the intended behavior should be on my side? The errors look something like:

Unexpected non-whitespace character after JSON at position {}

My assumption is that this is due to the partial tweets received from Twitter, where the buffer gets corrupted and the tweet isn't JSON-parsable. I have reconnect logic in the case of errors which seems to work well, but my question is: is this error actionable? As far as I can tell we don't have access to the corrupted JSON itself, but I'm curious what I should be doing when this signal occurs, if anything?

Thank you in advance!