From a9087f026297a9ed0bb5f27c31ce203078d0d6fa Mon Sep 17 00:00:00 2001 From: lefherz Date: Sun, 2 Jun 2019 16:17:57 +0200 Subject: extended MastodonServerError for all 5xx error codes --- mastodon/Mastodon.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 65ce518..bfc2a9b 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -2750,7 +2750,8 @@ class Mastodon: # on any 404 elif response_object.status_code == 401: ex_type = MastodonUnauthorizedError - elif response_object.status_code == 502: + elif response_object.status_code >= 500 and \ + response_object.status_code <= 511: ex_type = MastodonServerError else: ex_type = MastodonAPIError @@ -3068,7 +3069,7 @@ class MastodonAPIError(MastodonError): pass class MastodonServerError(MastodonError): - """Raised if the Server is malconfigured, e.g. returns a 502 error code""" + """Raised if the Server is malconfigured and returns a 5xx error code""" pass class MastodonNotFoundError(MastodonAPIError): -- cgit v1.2.3 From 21e12cfb58cf8c94d562e11823c5af00a0b16a4a Mon Sep 17 00:00:00 2001 From: lefherz Date: Sun, 2 Jun 2019 16:37:37 +0200 Subject: better inheritance cascade for HTTP error codes, implemented more errors --- mastodon/Mastodon.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index bfc2a9b..76c22cf 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -2750,6 +2750,14 @@ 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 @@ -3068,10 +3076,26 @@ class MastodonAPIError(MastodonError): """Raised when the mastodon API generates a response that cannot be handled""" pass -class MastodonServerError(MastodonError): +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): """Raised when the mastodon API returns a 404 Not Found error""" pass -- cgit v1.2.3 From c2e9760edc27a52eba2d8cda881c8c9aa1d4dc11 Mon Sep 17 00:00:00 2001 From: lefherz Date: Sun, 2 Jun 2019 16:40:11 +0200 Subject: added imports to __init__.py --- mastodon/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mastodon') diff --git a/mastodon/__init__.py b/mastodon/__init__.py index 1be4aba..047ffb7 100644 --- a/mastodon/__init__.py +++ b/mastodon/__init__.py @@ -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'] -- cgit v1.2.3 From e6ed107fdf2c96bf1c698b212e3e0d4a1102e4d0 Mon Sep 17 00:00:00 2001 From: lefherz Date: Wed, 5 Jun 2019 11:44:20 +0200 Subject: fixed typo --- mastodon/Mastodon.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 76c22cf..ef71078 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -3080,19 +3080,19 @@ class MastodonServerError(MastodonAPIError): """Raised if the Server is malconfigured and returns a 5xx error code""" pass -class MastodonInternalServerError(MastodonServerError) +class MastodonInternalServerError(MastodonServerError): """Raised if the Server returns a 500 error""" pass -class MastodonBadGatewayError(MastodonServerError) +class MastodonBadGatewayError(MastodonServerError): """Raised if the Server returns a 502 error""" pass -class MastodonServiceUnavailableError(MastodonServerError) +class MastodonServiceUnavailableError(MastodonServerError): """Raised if the Server returns a 503 error""" pass -class MastodonGatewayTimeoutError(MastodonServerError) +class MastodonGatewayTimeoutError(MastodonServerError): """Raised if the Server returns a 504 error""" pass -- cgit v1.2.3