fix(api): degrade recent event readback failures
All checks were successful
CD Pipeline / workflow-shape (push) Successful in 1s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 2m26s
CD Pipeline / build-and-deploy (push) Successful in 4m41s
CD Pipeline / post-deploy-checks (push) Successful in 4m49s

This commit is contained in:
ogt
2026-07-09 19:46:14 +08:00
parent 607c5e5a40
commit 13ce6218ae
2 changed files with 52 additions and 6 deletions

View File

@@ -118,6 +118,8 @@ class RecentEventsResponse(BaseModel):
events: list[ChannelEventItem]
total: int
limit: int
source_status: str = "ready"
source_error: str | None = None
class ChannelEventDossierItem(BaseModel):
@@ -667,9 +669,26 @@ async def list_recent_events(
),
limit: int = Query(20, ge=1, le=100, description="最多返回筆數"),
) -> dict[str, Any]:
return await list_recent_channel_events(
project_id=project_id,
channel_type=channel_type,
provider_prefix=provider_prefix,
limit=limit,
)
try:
return await list_recent_channel_events(
project_id=project_id,
channel_type=channel_type,
provider_prefix=provider_prefix,
limit=limit,
)
except Exception as exc:
logger.warning(
"recent_channel_events_source_unavailable",
project_id=project_id or "awoooi",
channel_type=channel_type,
provider_prefix=provider_prefix,
limit=limit,
error=exc.__class__.__name__,
)
return {
"events": [],
"total": 0,
"limit": max(1, min(limit, 100)),
"source_status": "source_unavailable",
"source_error": exc.__class__.__name__,
}