Return skipped status for Telegram poll limits
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 30s

This commit is contained in:
Grendgi
2026-06-08 23:29:38 +03:00
parent 5165b31910
commit 29490e5f93

View File

@@ -72,15 +72,16 @@ async def _require_channel_scope(
raise HTTPException(status_code=404)
def _poll_http_error(exc: PollError) -> HTTPException:
headers = None
def _poll_skipped_result(exc: PollError) -> dict[str, Any]:
result: dict[str, Any] = {
"inserted": 0,
"status": "skipped",
"code": exc.code,
"message": exc.message,
}
if exc.retry_after is not None:
headers = {"Retry-After": str(exc.retry_after)}
return HTTPException(
status_code=exc.status_code,
detail={"code": exc.code, "message": exc.message},
headers=headers,
)
result["retry_after"] = exc.retry_after
return result
@router.get("/auth/status", response_model=AuthStatus, dependencies=[Depends(require_telegram_auth_manager)])
@@ -137,13 +138,13 @@ async def trigger_poll(
vertical: str | None = Query(None),
section: str | None = Query(None),
session: AsyncSession = Depends(get_session),
) -> dict[str, int]:
) -> dict[str, Any]:
await _require_channel_scope(session, request, channel_id, vertical, section)
try:
inserted = await poll_channel(channel_id)
except PollError as exc:
raise _poll_http_error(exc)
return {"inserted": inserted}
return _poll_skipped_result(exc)
return {"inserted": inserted, "status": "ok"}
@router.post(