Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/musher/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def _raise_for_status(response: httpx.Response) -> None:
raise AuthenticationError("Invalid or missing API token")

if status == 404: # noqa: PLR2004
raise BundleNotFoundError(str(response.url))
try:
body_404: dict[str, object] = response.json() # pyright: ignore[reportAny]
detail_404 = str(body_404.get("detail", ""))
except (ValueError, KeyError):
detail_404 = ""
raise BundleNotFoundError(detail_404 or str(response.url))

if status == 429: # noqa: PLR2004
retry_after_header: str | None = response.headers.get("Retry-After") # pyright: ignore[reportAny]
Expand Down
16 changes: 16 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ async def test_404_raises_bundle_not_found(self, transport: HTTPTransport):
with pytest.raises(BundleNotFoundError):
await transport.get("/v1/test")

@respx.mock
async def test_404_with_json_body_uses_detail(self, transport: HTTPTransport):
respx.get("https://api.test.dev/v1/test").mock(
return_value=httpx.Response(
404,
json={
"type": "https://api.platform.musher.dev/errors/not-found",
"title": "Resource Not Found",
"status": 404,
"detail": "Bundle version with identifier '1.0.0' not found",
},
)
)
with pytest.raises(BundleNotFoundError, match="Bundle version with identifier"):
await transport.get("/v1/test")

@respx.mock
async def test_429_raises_rate_limit_with_retry_after(self, transport: HTTPTransport):
respx.get("https://api.test.dev/v1/test").mock(
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading