diff options
author | Lorenz Diener <[email protected]> | 2018-06-04 17:58:11 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2018-06-04 17:58:11 +0200 |
commit | b663394c6da1dee2069be6549deed0012d5f0285 (patch) | |
tree | a0fba9e20aca1ca0128f7ee5fba2fed30a0be848 /mastodon | |
parent | e1bac5b69ee1777a57a565956164bfb1dfd8bb41 (diff) | |
download | mastodon.py-b663394c6da1dee2069be6549deed0012d5f0285.tar.gz |
Streaming error handler
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/streaming.py | 7 |
1 files changed, 7 insertions, 0 deletions
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): | |||
25 | describing the notification.""" | 25 | describing the notification.""" |
26 | pass | 26 | pass |
27 | 27 | ||
28 | def on_abort(self): | ||
29 | """Some error happened that requires that the connection should | ||
30 | be aborted (or re-established)""" | ||
31 | pass | ||
32 | |||
28 | def on_delete(self, status_id): | 33 | def on_delete(self, status_id): |
29 | """A status has been deleted. status_id is the status' integer ID.""" | 34 | """A status has been deleted. status_id is the status' integer ID.""" |
30 | pass | 35 | pass |
@@ -64,11 +69,13 @@ class StreamListener(object): | |||
64 | else: | 69 | else: |
65 | line_buffer.extend(chunk) | 70 | line_buffer.extend(chunk) |
66 | except ChunkedEncodingError as err: | 71 | except ChunkedEncodingError as err: |
72 | self.on_abort() | ||
67 | six.raise_from( | 73 | six.raise_from( |
68 | MastodonNetworkError("Server ceased communication."), | 74 | MastodonNetworkError("Server ceased communication."), |
69 | err | 75 | err |
70 | ) | 76 | ) |
71 | except MastodonReadTimeout as err: | 77 | except MastodonReadTimeout as err: |
78 | self.on_abort() | ||
72 | six.raise_from( | 79 | six.raise_from( |
73 | MastodonReadTimeout("Timed out while reading from server."), | 80 | MastodonReadTimeout("Timed out while reading from server."), |
74 | err | 81 | err |