diff --git a/server.py b/server.py index 04dbdb5..3221175 100644 --- a/server.py +++ b/server.py @@ -261,8 +261,13 @@ def preview_url( response = client.send(response.next_request) if response.status_code not in range(200, 400): response.raise_for_status() - except httpx.HTTPError as e: - raise HTTPException(500, f"Failed to fetch URL: {e!r}") + except httpx.HTTPStatusError as e: + if e.response.status_code in (204, 400, 401, 403, 405, 429, 410): + return JSONResponse({}, e.response.status_code, {"Cache-Control": "no-store"}) + raise HTTPException( + e.response.status_code, + f"Failed to fetch {e.response.url} - HTTP {e.response.status_code}: {e.response.text}" + ) if "text/html" not in response.headers.get("content-type", ""): return {}