twitter-v2 icon indicating copy to clipboard operation
twitter-v2 copied to clipboard

- Sometimes Twitter API return "Rate Limit Exceeded" as text. JSON pa…

Open spidgorny opened this issue 3 years ago • 3 comments

  • Sometimes Twitter API return "Rate Limit Exceeded" as text. JSON parsing fails in this case. Fixed by detecting content-type header and returning either {data: } or {text: string} in get() method
  • When using pagination, it's important to fetch the "meta" data with pagination token. Changed so it returns both like this: {data, meta, headers}

spidgorny avatar Apr 15 '21 18:04 spidgorny

This change makes sense to me, however I'd prefer not to change the current return types of utility methods:

  • get(...)
  • post(...)
  • delete(...)

I'd prefer to maintain backwards compatibility. If JSON is not returned I'd imagine we can safely throw an error with the text value instead (see TwitterError.js) Thoughts?

HunterLarco avatar Apr 20 '21 13:04 HunterLarco

Yes, Rate-Limit is more like an exceptional case - I like the idea to throw an Error.

spidgorny avatar Apr 20 '21 16:04 spidgorny

This also happens if the path is incorrect (e.g. if the path is set to /users instead of users) - the 404 response is HTML.

Throwing an error with the contents of response.status and await response.text() would be useful.

It might be a good idea to check for response.ok before trying to parse the JSON?

hubgit avatar Aug 13 '21 08:08 hubgit