Skip to content

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

Open
spidgorny wants to merge 1 commit into
HunterLarco:masterfrom
spidgorny:get-request-with-meta-and-headers
Open

spidgorny wants to merge 1 commit into
HunterLarco:masterfrom
spidgorny:get-request-with-meta-and-headers

Conversation

@spidgorny

Copy link
Copy Markdown
  • 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}

…rsing fails in this case. Fixed by detecting content-type header and returning either {data: <json>} 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}
@HunterLarco

Copy link
Copy Markdown
Owner

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?

@spidgorny

Copy link
Copy Markdown
Author

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

@hubgit

hubgit commented Aug 13, 2021

Copy link
Copy Markdown

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants