HunterLarco / twitter-v2

An asynchronous client library for the Twitter REST and Streaming API's
MIT License
163 stars 35 forks source link

Handle .errors[] in streams #94

Open arty-name opened 3 years ago

arty-name commented 3 years ago

Prerequisites

Summary

Some chunks coming from the stream API look like the example below. First, would it make sense to report whatever is coming in .errors[] as TwitterError? Second, would the code become more elegant by disconnecting explicitly on receiving OperationalDisconnect?

const chunk = {
  errors: [
    {
      title: 'operational-disconnect',
      disconnect_type: 'OperationalDisconnect',
      detail: 'This stream has been disconnected for operational reasons.',
      type: 'https://api.twitter.com/2/problems/operational-disconnect',
    },
  ],
}

Motivation

My code was naively expecting to receive consistently formed chunks and errored out on this unexpected shape. Which is kind of fine, but since this is an explicit error, it probably would make sense to centralize its handling in the twitter-v2.

Describe alternatives you've considered

Leaving this for all library users to handle by themselves is also an option, a wasteful one though.

Additional context