Error logging

This commit is contained in:
sistav committed 2026-07-15 18:44:29 -04:00
1 parent f4c1efb454
commit 6867e93a30
1 file changed
+10 -3
+10 -3
View File
@@ -1,19 +1,26 @@
import logging
import os
from urllib.parse import quote
import httpx
from fastapi import HTTPException
logger = logging.getLogger("uvicorn.error")
BASE_URL = "https://api.chess.com/pub"
HEADERS = {"User-Agent": os.environ.get("CHESSCOM_USER_AGENT", "chess.sistav.com")}
HEADERS = {"User-Agent": os.environ.get("USER_AGENT", "chess.sistav.com")}
UPSTREAM_ERROR = "chess.com isn't responding right now. Try again in a minute."
async def _get(url: str, timeout: float) -> httpx.Response:
try:
async with httpx.AsyncClient(headers=HEADERS, timeout=timeout) as client:
return await client.get(url)
except httpx.HTTPError:
resp = await client.get(url)
except httpx.HTTPError as exc:
logger.warning("chess.com request failed for %s: %r", url, exc)
raise HTTPException(status_code=502, detail=UPSTREAM_ERROR)
if resp.status_code not in (200, 404):
logger.warning("chess.com returned %s for %s", resp.status_code, url)
return resp
async def get_archives(username: str) -> list[str]: