Skip to content

Commit

Permalink
Handle any 451's as if they were 404s
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Jul 7, 2024
1 parent 6161462 commit 3236a8f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/adapters/osu_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/adapters/osu_api_v2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion app/adapters/osu_mirrors/backends/gatari.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/adapters/osu_mirrors/backends/mino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/adapters/osu_mirrors/backends/nerinyan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/adapters/osu_mirrors/backends/osu_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/adapters/osu_mirrors/backends/ripple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3236a8f

Please sign in to comment.