koala73/worldmonitor · error
Invalid Telegram feed response
Error message
Invalid Telegram feed response
What it means
parseTelegramFeedResponse requires the parsed body to be an object with an items array; anything else (null body, wrong shape, items not an array) throws 'Invalid Telegram feed response'. Notably, individual bad items inside a valid array are dropped rather than throwing — this error is reserved for the top-level envelope being wrong, because throwing on one malformed post previously blanked the whole panel.
Source
Thrown at src/services/telegram-intel.ts:189
return {
id: parsed.id as string,
source: 'telegram',
channel: parsed.channel as string,
channelTitle: parsed.channelTitle as string,
url: parsed.url as string,
ts: parsed.ts as string,
text: parsed.text as string,
topic: parsed.topic as string,
tags: parsed.tags,
earlySignal: parsed.earlySignal !== false,
...(Array.isArray(parsed.mediaUrls) ? { mediaUrls: parsed.mediaUrls.filter(value => typeof value === 'string') } : {}),
...(parsed.watchlist === true ? { watchlist: true } : {}),
};
}
function parseTelegramFeedResponse(value: unknown): TelegramFeedResponse {
const parsed = asRecord(value);
if (!parsed || !Array.isArray(parsed.items)) throw new Error('Invalid Telegram feed response');
// Drop unparseable items rather than rejecting the whole payload. Throwing
// here turned one malformed post into a blanked panel: the caller falls back
// to a <=10min stale copy and then to the disabled empty state, discarding
// intel that was on screen a moment earlier.
const items = parsed.items
.map(parseTelegramItem)
.filter((item): item is TelegramItem => item !== null);
return {
source: typeof parsed.source === 'string' ? parsed.source : 'telegram',
earlySignal: parsed.earlySignal !== false,
// `!== false`, not `=== true`: an omitted `enabled` is shape drift, and
// reading it as "relay disabled" renders a permanent not-active state over
// a feed that is actually fine.
enabled: parsed.enabled !== false,
count: items.length,
updatedAt: typeof parsed.updatedAt === 'string' ? parsed.updatedAt : null,
items,
};View on GitHub (pinned to 9361220cc0)
Solutions
- Verify response.ok and that content-type is application/json before feeding the parser.
- Deploy matching versions of the edge Telegram feed endpoint and the client parser; check for recent schema changes.
- Catch the error and fall back to the stale cached feed (the service keeps a <=10min stale copy) or the disabled empty state.
- Log the offending body to distinguish proxy interference from a real API contract break.
Example fix
// before
const feed = await fetchTelegramChannelFeed(username); // throws, panel blanks
// after
try {
const feed = await fetchTelegramChannelFeed(username);
renderFeed(feed.items);
} catch {
renderFeed(lastKnownItems ?? []); // stale or empty-state fallback
} Defensive patterns
Strategy: fallback
Validate before calling
const body = await res.json();
if (body == null || typeof body !== 'object' || !Array.isArray((body as any).items)) {
throw new Error('Malformed feed envelope');
}
Type guard
function isTelegramFeedResponse(v: unknown): v is TelegramFeedResponse {
return typeof v === 'object' && v !== null && Array.isArray((v as any).items);
}
Try / catch
let feed: TelegramFeedResponse | null = null;
try {
feed = await fetchTelegramChannelFeed(handle);
} catch {
feed = lastGoodFeed ?? null; // stale copy or null -> disabled empty state
}
renderFeed(feed?.items ?? []);
Prevention
- Keep a last-known-good feed and render it (marked stale) when a fetch fails
- Verify response.ok and JSON content-type before parsing
- Deploy client and edge schema changes together; smoke-test the feed envelope after edge deploys
- Never let a single panel failure blank adjacent panels — scope the catch to the feed
When it happens
Trigger: Calling fetchTelegramChannelFeed where the edge response body is not { items: [...] } — an HTML error page served with 200, a JSON error object without items, a truncated/empty body, or a contract change between client and deployed edge version.
Common situations: Edge function crash handlers returning { error } bodies with 200; CDN/proxy interception pages; deploying a new edge API while clients run an older schema; cache poisoning with non-feed payloads.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Invalid Telegram channel preview
- ${errorMessage}
- Invalid Telegram username
- get_intel_timeline requires at least one of domain ("conflic
- Exa returned no content for ${url}
AI-assisted analysis of koala73/worldmonitor@9361220cc0 (2026-09-01).
Data as JSON: /api/errors/c7a6864c9c59f01b.
Report an issue: GitHub.