From 89456fa7c74463ea83600eb5208895acaa4d159e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 9 Jan 2024 00:18:14 +0200 Subject: [PATCH 1/4] Add link to trakt api error code definitions --- trakt/errors.py | 1 + 1 file changed, 1 insertion(+) diff --git a/trakt/errors.py b/trakt/errors.py index 06ce1769..0515c4e8 100644 --- a/trakt/errors.py +++ b/trakt/errors.py @@ -13,6 +13,7 @@ 'BadResponseException', # Exceptions by HTTP status code + # https://trakt.docs.apiary.io/#introduction/status-codes 'BadRequestException', 'OAuthException', 'ForbiddenException', From 0f8c5b8ad736b1ac541a7479c69e76f8c0006619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 9 Jan 2024 00:18:28 +0200 Subject: [PATCH 2/4] Update MethodNotAllowedException message --- trakt/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trakt/errors.py b/trakt/errors.py index 0515c4e8..1a86ca75 100644 --- a/trakt/errors.py +++ b/trakt/errors.py @@ -77,7 +77,7 @@ class NotFoundException(TraktException): class MethodNotAllowedException(TraktException): """TraktException type to be raised when a 405 return code is received""" http_code = 405 - message = 'Method not Allowed' + message = 'Method Not Found - method doesn\'t exist' class ConflictException(TraktException): From f6992f89d990342727ad4ba66e22b0642b18406b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 9 Jan 2024 00:24:03 +0200 Subject: [PATCH 3/4] Add details RateLimitException to parse x-ratelimit header --- trakt/errors.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/trakt/errors.py b/trakt/errors.py index 1a86ca75..6488e0b0 100644 --- a/trakt/errors.py +++ b/trakt/errors.py @@ -107,6 +107,15 @@ class RateLimitException(TraktException): def retry_after(self): return int(self.response.headers.get("Retry-After", 1)) + @property + def details(self): + from json import JSONDecodeError, loads + + try: + return loads(self.response.headers.get("x-ratelimit", "")) + except JSONDecodeError: + return None + class TraktInternalException(TraktException): """TraktException type to be raised when a 500 error is raised""" From 961a95d7fd1d2c2ef4387a2b2180671bb90f4988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 9 Jan 2024 00:26:17 +0200 Subject: [PATCH 4/4] Get retry-after header lowercase This is how currently it's being served --- trakt/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trakt/errors.py b/trakt/errors.py index 6488e0b0..dfb555b1 100644 --- a/trakt/errors.py +++ b/trakt/errors.py @@ -105,7 +105,7 @@ class RateLimitException(TraktException): @property def retry_after(self): - return int(self.response.headers.get("Retry-After", 1)) + return int(self.response.headers.get("retry-after", 1)) @property def details(self):