Merge pull request #174 from lefherz/master

extended MastodonServerError for all 5xx error codes
pull/176/head
Lorenz Diener 2019-06-05 11:52:43 +02:00 zatwierdzone przez GitHub
commit 1a120f0393
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 29 dodań i 4 usunięć

Wyświetl plik

@ -2750,7 +2750,16 @@ class Mastodon:
# on any 404
elif response_object.status_code == 401:
ex_type = MastodonUnauthorizedError
elif response_object.status_code == 500:
ex_type = MastodonInternalServerError
elif response_object.status_code == 502:
ex_type = MastodonBadGatewayError
elif response_object.status_code == 503:
ex_type = MastodonServiceUnavailableError
elif response_object.status_code == 504:
ex_type = MastodonGatewayTimeoutError
elif response_object.status_code >= 500 and \
response_object.status_code <= 511:
ex_type = MastodonServerError
else:
ex_type = MastodonAPIError
@ -3067,8 +3076,24 @@ class MastodonAPIError(MastodonError):
"""Raised when the mastodon API generates a response that cannot be handled"""
pass
class MastodonServerError(MastodonError):
"""Raised if the Server is malconfigured, e.g. returns a 502 error code"""
class MastodonServerError(MastodonAPIError):
"""Raised if the Server is malconfigured and returns a 5xx error code"""
pass
class MastodonInternalServerError(MastodonServerError):
"""Raised if the Server returns a 500 error"""
pass
class MastodonBadGatewayError(MastodonServerError):
"""Raised if the Server returns a 502 error"""
pass
class MastodonServiceUnavailableError(MastodonServerError):
"""Raised if the Server returns a 503 error"""
pass
class MastodonGatewayTimeoutError(MastodonServerError):
"""Raised if the Server returns a 504 error"""
pass
class MastodonNotFoundError(MastodonAPIError):

Wyświetl plik

@ -1,5 +1,5 @@
from mastodon.Mastodon import Mastodon, AttribAccessDict, MastodonError, MastodonVersionError, MastodonIllegalArgumentError, MastodonIOError, MastodonFileNotFoundError, MastodonNetworkError, MastodonAPIError, MastodonNotFoundError, MastodonUnauthorizedError, MastodonRatelimitError, MastodonMalformedEventError, MastodonServerError
from mastodon.Mastodon import Mastodon, AttribAccessDict, MastodonError, MastodonVersionError, MastodonIllegalArgumentError, MastodonIOError, MastodonFileNotFoundError, MastodonNetworkError, MastodonAPIError, MastodonNotFoundError, MastodonUnauthorizedError, MastodonRatelimitError, MastodonMalformedEventError, MastodonServerError, MastodonInternalServerError, MastodonBadGatewayError, MastodonServiceUnavailableError, MastodonGatewayTimeoutError
from mastodon.streaming import StreamListener, CallbackStreamListener
__all__ = ['Mastodon', 'AttribAccessDict', 'StreamListener', 'CallbackStreamListener', 'MastodonError', 'MastodonVersionError', 'MastodonIllegalArgumentError', 'MastodonIOError', 'MastodonFileNotFoundError', 'MastodonNetworkError', 'MastodonAPIError', 'MastodonNotFoundError', 'MastodonUnauthorizedError', 'MastodonRatelimitError', 'MastodonMalformedEventError',
'MastodonServerError']
'MastodonServerError', 'MastodonInternalServerError', 'MastodonBadGatewayError', 'MastodonServiceUnavailableError', 'MastodonGatewayTimeoutError']