ChimeraCoder / anaconda

A Go client library for the Twitter 1.1 API
MIT License
1.14k stars 247 forks source link

How are custom error handlers supposed to be implemented whilst using PublicStreamFilter? #185

Open bradkyle opened 7 years ago

bradkyle commented 7 years ago

I am trying to create a custom error handler for the PublicStreamFilter function, more specifically I would like to log the rate limit errors to a file in the same directory. But the PublicStreamFilter function doesn't return an error. Does this mean that the PublicStreamFilter doesn't incur any errors?

Thus, how are custom error handling functions supposed to be implemented with the PublicStreamFilter function in use(streaming being the current objective)?

There is no explicit documentation in the godocs or implementation in the example_test.go .

gnobre commented 7 years ago

PublicStreamFilter returns a anaconda.LimitNotice with the number of undelivered tweets

cesarsalgado commented 7 years ago

I think the Stream struct should have an error channel and an status channel so the client code can possibly act upon the error or status code. For example, one can imagine a client code that wants to stop the stream upon the 420, instead of the default anaconda behavior that is to keep trying with exponential backoff.

Currently the only way to act upon an error is by creating your own Logger implementation that forward the messages received to channels and passing the logger to the TwitterApi struct upon creation. But this is not a very elegant solution.

I can make a pull request if there is interest in adopting this solution.

jnflint commented 6 years ago

@cesarsalgado I'd be interested in such a solution. As I understand the issue it is not possible/practical to get notification of the http status codes or errors that occur. I'd like to get this information so I could for instance, get missing tweets through the search api.