raise MastodonReadTimeout when a stream times out
This commit is contained in:
pare
2afc50c803
commit
06e32c14bc
S'han modificat 2 arxius amb 12 adicions i 3 eliminacions
|
@ -1872,6 +1872,10 @@ class MastodonNetworkError(MastodonIOError):
|
||||||
"""Raised when network communication with the server fails"""
|
"""Raised when network communication with the server fails"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class MastodonReadTimeout(MastodonNetworkError):
|
||||||
|
"""Raised when a stream times out"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MastodonAPIError(MastodonError):
|
class MastodonAPIError(MastodonError):
|
||||||
"""Raised when the mastodon API generates a response that cannot be handled"""
|
"""Raised when the mastodon API generates a response that cannot be handled"""
|
||||||
|
|
|
@ -6,8 +6,8 @@ https://github.com/tootsuite/mastodon/blob/master/docs/Using-the-API/Streaming-A
|
||||||
import json
|
import json
|
||||||
import six
|
import six
|
||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
from mastodon.Mastodon import MastodonMalformedEventError, MastodonNetworkError
|
from mastodon.Mastodon import MastodonMalformedEventError, MastodonNetworkError, MastodonReadTimeout
|
||||||
from requests.exceptions import ChunkedEncodingError
|
from requests.exceptions import ChunkedEncodingError, ReadTimeout
|
||||||
|
|
||||||
class StreamListener(object):
|
class StreamListener(object):
|
||||||
"""Callbacks for the streaming API. Create a subclass, override the on_xxx
|
"""Callbacks for the streaming API. Create a subclass, override the on_xxx
|
||||||
|
@ -68,6 +68,11 @@ class StreamListener(object):
|
||||||
MastodonNetworkError("Server ceased communication."),
|
MastodonNetworkError("Server ceased communication."),
|
||||||
err
|
err
|
||||||
)
|
)
|
||||||
|
except MastodonReadTimeout as err:
|
||||||
|
six.raise_from(
|
||||||
|
MastodonReadTimeout("Timed out while reading from server."),
|
||||||
|
err
|
||||||
|
)
|
||||||
|
|
||||||
def _parse_line(self, line, event):
|
def _parse_line(self, line, event):
|
||||||
if line.startswith(':'):
|
if line.startswith(':'):
|
||||||
|
|
Loading…
Referencia en una nova incidència