draftbit / twitter-lite

A tiny, full-featured, flexible client / server library for the Twitter API
https://npm.im/twitter-lite
MIT License
794 stars 96 forks source link

Rate limit handling could be more explicit #168

Open lagoa89 opened 3 years ago

lagoa89 commented 3 years ago

First off thanks to you all for devloping such a helpful library. I really appreciate it.

I'm making a call to a users timeline to retrieve mentions. When the rate limit is hit twitter returns a 429 response with "Rate limit exceeded" in the body. Twitter-lite throws the following error: message: 'invalid json response body at https://api.twitter.com/2/users/****/mentions?tweet.fields=created_at%2Cauthor_id%2Cin_reply_to_user_id&max_results=100 reason: Unexpected token R in JSON at position 0', type: 'invalid-json'

It would be easier to handle this appropriately (e.g. exponential back-off) if the HTTP code was returned in the errors object.

I suspect twitter.js L104 is the reason this is thrown.

Please let me know if there is any more information you need. Thanks again.