Skip to content

Conversation

@samlbest
Copy link

I was getting an error when trying to recreate the stream request with new variables:

SyntaxError: Unexpected token E

This was an error originating in the JSON parser because the response was just 'Exceeded connection limit for user'. I found that this error comes along with the 420 status code (https://dev.twitter.com/streaming/overview/connecting).

The fix I added will handle the 420 response status code by ending the current request and setting a timeout to call the stream function again after 10 seconds. If new calls to stream come in during that timeout period, no new request will be created but stream will be called with the latest parameters when the timeout ends:

For example:

stream('dog') called (by client application)
420 status code - 10s timeout
stream('cat') called  (by client application) - no new request created, but 'cat' parameter stored
...10 seconds later
stream('cat') called (by timeOut) because it uses the new parameter

Twitter actually recommends backing off for 1 minute for a 420 status code, then doubling that wait for each subsequent 420 response. I didn't find that long of a wait to be necessary, but if you would like me to I can update my implementation to behave like that.

@dan-petty
Copy link

I'm getting this error as well...
[SyntaxError: Unexpected token E] source: 'Exceeded connection limit for user'

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.

2 participants