From b663394c6da1dee2069be6549deed0012d5f0285 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Mon, 4 Jun 2018 17:58:11 +0200 Subject: Streaming error handler --- mastodon/streaming.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'mastodon') diff --git a/mastodon/streaming.py b/mastodon/streaming.py index 3fbd569..416f271 100644 --- a/mastodon/streaming.py +++ b/mastodon/streaming.py @@ -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 -- cgit v1.2.3