From b378110dc077952b93a26dbd5a8aea60b2f0e217 Mon Sep 17 00:00:00 2001 From: Lucas Hardt Date: Wed, 27 Nov 2024 22:46:36 +0100 Subject: [PATCH 1/2] fix Asset.resize to raise ValueError instead of TypeError when the given size isn't a power of 2 --- docs/changelog.rst | 1 + fortnite_api/asset.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 90bc9199..5959990f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,6 +13,7 @@ v3.3.0 Bug Fixes ~~~~~~~~~ - Fixed an issue that caused a :class:`KeyError` to be raised when using :meth:`fortnite_api.Client.search_br_cosmetics` or :meth:`fortnite_api.SyncClient.search_br_cosmetics` without `multiple` parameter. +- Fixed an issue that caused :class:`fortnite_api.Asset.resize` to raise :class:`TypeError` instead of :class:`ValueError` when the given size isn't a power of 2. .. _vp3p2p0: diff --git a/fortnite_api/asset.py b/fortnite_api/asset.py index 60baf2fa..df99ce50 100644 --- a/fortnite_api/asset.py +++ b/fortnite_api/asset.py @@ -146,7 +146,7 @@ def resize(self, size: int) -> Self: raise ValueError('This asset does not support resizing.') if (size & (size - 1) != 0) or size <= 0: - raise TypeError('Size must be a power of 2.') + raise ValueError('Size must be a power of 2.') if self._max_size is not None: if size > self._max_size: From a824c73b2db6c94925ad6c7e67c1047c9ba44c6d Mon Sep 17 00:00:00 2001 From: Lucas Hardt Date: Mon, 2 Dec 2024 07:43:36 +0100 Subject: [PATCH 2/2] Improve fallback error handling (#37) --- docs/changelog.rst | 1 + fortnite_api/http.py | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5959990f..c300f8ba 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,6 +14,7 @@ Bug Fixes ~~~~~~~~~ - Fixed an issue that caused a :class:`KeyError` to be raised when using :meth:`fortnite_api.Client.search_br_cosmetics` or :meth:`fortnite_api.SyncClient.search_br_cosmetics` without `multiple` parameter. - Fixed an issue that caused :class:`fortnite_api.Asset.resize` to raise :class:`TypeError` instead of :class:`ValueError` when the given size isn't a power of 2. +- Fixed an issue that caused :class:`fortnite_api.ServiceUnavailable` to be raised with a static message as a fallback for all unhandled http status codes. Instead :class:`fortnite_api.HTTPException` is raised with the proper error message. .. _vp3p2p0: diff --git a/fortnite_api/http.py b/fortnite_api/http.py index 551e4b67..4147cc7b 100644 --- a/fortnite_api/http.py +++ b/fortnite_api/http.py @@ -426,19 +426,18 @@ async def request(self, route: Route, **kwargs: Any) -> Any: continue - if response.status in {500, 502, 504}: + if response.status > 500: await asyncio.sleep(1 + tries * 2) continue - if response.status > 500: - raise ServiceUnavailable(error, response, data) - if response is not None: # If we hit the limit 5 times, there are bigger issues. if response.status == 429: raise RateLimited(error, response, data) + if response.status > 500: + raise ServiceUnavailable(error, response, data) - raise ServiceUnavailable('Service unavailable', response, data) + raise HTTPException(error, response, data) raise RuntimeError('Unreachable code reached!') @@ -518,17 +517,17 @@ def request(self, route: Route, **kwargs: Any) -> Any: continue - if response.status_code in {500, 502, 504}: + if response.status_code > 500: time.sleep(1 + tries * 2) continue - if response.status_code > 500: - raise ServiceUnavailable(error, response, data) - if response is not None: + # If we hit the limit 5 times, there are bigger issues. if response.status_code == 429: raise RateLimited(error, response, data) + if response.status_code > 500: + raise ServiceUnavailable(error, response, data) - raise ServiceUnavailable('Service unavailable', response, data) + raise HTTPException(error, response, data) raise RuntimeError('Unreachable code reached!')