twitter-v2
twitter-v2 copied to clipboard
- Sometimes Twitter API return "Rate Limit Exceeded" as text. JSON pa…
- 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}
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?
Yes, Rate-Limit is more like an exceptional case - I like the idea to throw an Error.
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?