From 3236a8f632d77275fcde3fc74a8f9e8dfe08cabd Mon Sep 17 00:00:00 2001 From: cmyui Date: Sun, 7 Jul 2024 06:32:32 -0400 Subject: [PATCH] Handle any 451's as if they were 404s --- app/adapters/osu_api_v1.py | 4 ++-- app/adapters/osu_api_v2/api.py | 4 ++-- app/adapters/osu_mirrors/backends/gatari.py | 2 +- app/adapters/osu_mirrors/backends/mino.py | 4 ++-- app/adapters/osu_mirrors/backends/nerinyan.py | 2 +- app/adapters/osu_mirrors/backends/osu_direct.py | 4 ++-- app/adapters/osu_mirrors/backends/ripple.py | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/adapters/osu_api_v1.py b/app/adapters/osu_api_v1.py index c7bebbb..990e32d 100644 --- a/app/adapters/osu_api_v1.py +++ b/app/adapters/osu_api_v1.py @@ -82,7 +82,7 @@ async def fetch_one_beatmap( "authorized": True, }, ) - if response.status_code == 404: + if response.status_code in (404, 451): return None if response.status_code == 403: raise ValueError("osu api is down") from None @@ -113,7 +113,7 @@ async def fetch_beatmap_osu_file_data(beatmap_id: int) -> bytes | None: "authorized": False, }, ) - if response.status_code == 404: + if response.status_code in (404, 451): return None if response.status_code == 403: raise ValueError("osu api is down") from None diff --git a/app/adapters/osu_api_v2/api.py b/app/adapters/osu_api_v2/api.py index fb38492..06a26b6 100644 --- a/app/adapters/osu_api_v2/api.py +++ b/app/adapters/osu_api_v2/api.py @@ -38,7 +38,7 @@ async def get_beatmap(beatmap_id: int) -> BeatmapExtended | None: osu_api_response_data: dict[str, Any] | None = None try: response = await osu_api_v2_http_client.get(f"beatmaps/{beatmap_id}") - if response.status_code == 404: + if response.status_code in (404, 451): return None response.raise_for_status() osu_api_response_data = response.json() @@ -59,7 +59,7 @@ async def get_beatmapset(beatmapset_id: int) -> BeatmapsetExtended | None: osu_api_response_data: dict[str, Any] | None = None try: response = await osu_api_v2_http_client.get(f"beatmapsets/{beatmapset_id}") - if response.status_code == 404: + if response.status_code in (404, 451): return None response.raise_for_status() osu_api_response_data = response.json() diff --git a/app/adapters/osu_mirrors/backends/gatari.py b/app/adapters/osu_mirrors/backends/gatari.py index 2505863..8f1d3af 100644 --- a/app/adapters/osu_mirrors/backends/gatari.py +++ b/app/adapters/osu_mirrors/backends/gatari.py @@ -24,7 +24,7 @@ async def fetch_beatmap_zip_data( f"{self.base_url}/d/{beatmapset_id}", follow_redirects=True, ) - if response.status_code == 404: + if response.status_code in (404, 451): return BeatmapMirrorResponse( data=None, is_success=True, diff --git a/app/adapters/osu_mirrors/backends/mino.py b/app/adapters/osu_mirrors/backends/mino.py index 005bc28..cac9677 100644 --- a/app/adapters/osu_mirrors/backends/mino.py +++ b/app/adapters/osu_mirrors/backends/mino.py @@ -26,7 +26,7 @@ async def fetch_beatmap_zip_data( headers={"x-ratelimit-key": settings.MINO_INCREASED_RATELIMIT_KEY}, timeout=httpx.Timeout(None, connect=2), ) - if response.status_code == 404: + if response.status_code in (404, 451): return BeatmapMirrorResponse( data=None, is_success=True, @@ -61,7 +61,7 @@ async def fetch_beatmap_background_image( f"{self.base_url}/preview/background/{beatmap_id}", timeout=httpx.Timeout(None, connect=2), ) - if response.status_code == 404: + if response.status_code in (404, 451): return BeatmapMirrorResponse( data=None, is_success=True, diff --git a/app/adapters/osu_mirrors/backends/nerinyan.py b/app/adapters/osu_mirrors/backends/nerinyan.py index 93ce424..351794b 100644 --- a/app/adapters/osu_mirrors/backends/nerinyan.py +++ b/app/adapters/osu_mirrors/backends/nerinyan.py @@ -23,7 +23,7 @@ async def fetch_beatmap_zip_data( response = await self.http_client.get( f"{self.base_url}/d/{beatmapset_id}", ) - if response.status_code == 404: + if response.status_code in (404, 451): return BeatmapMirrorResponse( data=None, is_success=True, diff --git a/app/adapters/osu_mirrors/backends/osu_direct.py b/app/adapters/osu_mirrors/backends/osu_direct.py index 01ebe9f..26ac76e 100644 --- a/app/adapters/osu_mirrors/backends/osu_direct.py +++ b/app/adapters/osu_mirrors/backends/osu_direct.py @@ -24,7 +24,7 @@ async def fetch_beatmap_zip_data( f"{self.base_url}/api/d/{beatmapset_id}", timeout=httpx.Timeout(None, connect=2), ) - if response.status_code == 404: + if response.status_code in (404, 451): return BeatmapMirrorResponse( data=None, is_success=True, @@ -58,7 +58,7 @@ async def fetch_beatmap_background_image( f"{self.base_url}/api/media/background/{beatmap_id}", timeout=httpx.Timeout(None, connect=2), ) - if response.status_code == 404: + if response.status_code in (404, 451): return BeatmapMirrorResponse( data=None, is_success=True, diff --git a/app/adapters/osu_mirrors/backends/ripple.py b/app/adapters/osu_mirrors/backends/ripple.py index de68cfc..140e3e0 100644 --- a/app/adapters/osu_mirrors/backends/ripple.py +++ b/app/adapters/osu_mirrors/backends/ripple.py @@ -21,7 +21,7 @@ async def fetch_beatmap_zip_data( response = await self.http_client.get( f"{self.base_url}/d/{beatmapset_id}", ) - if response.status_code == 404: + if response.status_code in (404, 451): return BeatmapMirrorResponse( data=None, is_success=True,