feat: improve error handling in HTTP requests and database fixture loading

This commit is contained in:
gabdevele
2026-06-18 01:06:59 +02:00 Unverified
parent 07547ce2c3
commit 929f829d37
3 changed files with 54 additions and 13 deletions
@@ -2,12 +2,26 @@ import aiohttp
import asyncio
def _body_preview(body: str, limit: int = 256) -> str:
if not body:
return ""
preview = body[:limit].strip()
if len(body) > limit:
return f"{preview}..."
return preview
async def fetch(session, url, httpc_params: dict = {}):
async with session.get(url, **httpc_params.get("connection", {})) as response:
body = await response.text()
if response.status != 200: # pragma: no cover
# response.raise_for_status()
return ""
return await response.text()
raise RuntimeError(
"HTTP GET failed for "
f"{url}: status={response.status} "
f"content_type={response.headers.get('Content-Type', '')} "
f"body_preview={_body_preview(body)}"
)
return body
async def fetch_all(session, urls, httpc_params):