Fix: use pydantic pattern; handle httpx RequestError in gateway and qdrant

This commit is contained in:
2026-03-21 10:07:20 +01:00
parent e6da9924ff
commit ecf8c9a401
3 changed files with 25 additions and 7 deletions

View File

@@ -59,7 +59,10 @@ async def _get_health(client: httpx.AsyncClient, base: str) -> Dict[str, Any]:
async def _post_json(client: httpx.AsyncClient, url: str, payload: Dict[str, Any]) -> Dict[str, Any]:
r = await client.post(url, json=payload)
try:
r = await client.post(url, json=payload)
except httpx.RequestError as e:
raise HTTPException(status_code=502, detail=f"Upstream request failed {url}: {str(e)}")
if r.status_code >= 400:
raise HTTPException(status_code=502, detail=f"Upstream error {url}: {r.status_code} {r.text[:1000]}")
try:
@@ -71,7 +74,10 @@ async def _post_json(client: httpx.AsyncClient, url: str, payload: Dict[str, Any
async def _post_file(client: httpx.AsyncClient, url: str, data: bytes, fields: Dict[str, Any]) -> Dict[str, Any]:
files = {"file": ("image", data, "application/octet-stream")}
r = await client.post(url, data={k: str(v) for k, v in fields.items()}, files=files)
try:
r = await client.post(url, data={k: str(v) for k, v in fields.items()}, files=files)
except httpx.RequestError as e:
raise HTTPException(status_code=502, detail=f"Upstream request failed {url}: {str(e)}")
if r.status_code >= 400:
raise HTTPException(status_code=502, detail=f"Upstream error {url}: {r.status_code} {r.text[:1000]}")
try: