diff --git a/src/parser_bot/api/routes.py b/src/parser_bot/api/routes.py index dbdf640..d12a199 100644 --- a/src/parser_bot/api/routes.py +++ b/src/parser_bot/api/routes.py @@ -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(