Streaming error handler

This commit is contained in:
Lorenz Diener 2018-06-04 17:58:11 +02:00
pare e1bac5b69e
commit b663394c6d
S'han modificat 3 arxius amb 9 adicions i 0 eliminacions

Veure arxiu

@ -4,6 +4,7 @@ Here's some general stuff to keep in mind, and some work that needs to be done
use requests over urllib, et cetera.
* Current TODOs:
* Stream since_id and better resume
* Testing - test 2.3 stuff and verify it works, test pinning
* 2.4 support:
* Dict updates (bot flag, profile meta fields, ...?)

Veure arxiu

@ -227,6 +227,7 @@ User dicts
# from account_verify_credentials()
'moved_to_account': # If set, an account dict of the account this user has
# set up as their moved-to address.
'bot': # Boolean indicating whether this account is automated.
}
mastodon.account_verify_credentials()["source"]

Veure arxiu

@ -25,6 +25,11 @@ class StreamListener(object):
describing the notification."""
pass
def on_abort(self):
"""Some error happened that requires that the connection should
be aborted (or re-established)"""
pass
def on_delete(self, status_id):
"""A status has been deleted. status_id is the status' integer ID."""
pass
@ -64,11 +69,13 @@ class StreamListener(object):
else:
line_buffer.extend(chunk)
except ChunkedEncodingError as err:
self.on_abort()
six.raise_from(
MastodonNetworkError("Server ceased communication."),
err
)
except MastodonReadTimeout as err:
self.on_abort()
six.raise_from(
MastodonReadTimeout("Timed out while reading from server."),
err