DIYgod/RSSHub · error · Error
Failed to fetch announcements
Error message
Failed to fetch announcements
What it means
Generic Error thrown after cache.tryGet returns when the resolved value is falsy. Because the cache call passes cacheErrorFlag=false, a failed (throwing) getter is not cached — but a previously cached null/undefined, or a getter returning a falsy value, would surface here as a defensive empty-check before accessing response.data.items.
Source
Thrown at lib/routes/bitget/announcement.ts:85
const response = (await cache.tryGet(
`bitget:announcement:${type}:${pageSize}:${lang}`,
async () => {
const result = await ofetch<BitgetResponse>(announcementApiUrl, {
method: 'POST',
body: reqBody,
headers,
});
if (result?.code !== '200') {
throw new Error('Failed to fetch announcements, error code: ' + result?.code);
}
return result;
},
config.cache.routeExpire,
false
)) as BitgetResponse;
if (!response) {
throw new Error('Failed to fetch announcements');
}
const items = response.data.items;
const data = await Promise.all(
items.map(
(item) =>
cache.tryGet(`bitget:announcement:${item.id}:${pageSize}:${lang}`, async () => {
// 从 unix 时间戳转换为日期
const date = parseDate(Number(item.sendTime));
const dataItem: DataItem = {
title: item.title ?? '',
link: item.openUrl ?? '',
pubDate: item.sendTime ? date : undefined,
description: item.content ?? '',
image: item.imgUrl,
};
if (item.stationLetterType === '01' || item.stationLetterType === '06') {
try {View on GitHub (pinned to bed535e087)
Solutions
- Clear the affected cache key (bitget:announcement:*) or restart with a fresh cache.
- Confirm the getter in cache.tryGet actually returns the BitgetResponse object (not undefined) on success.
- Verify the Bitget API is currently returning data (see error 126) so the getter does not consistently fail.
Example fix
// before
if (!response) {
throw new Error('Failed to fetch announcements');
}
// after (name the cache key so operators can purge it)
if (!response) {
throw new Error('Failed to fetch announcements (empty response — purge cache key bitget:announcement:* )');
} Defensive patterns
Strategy: fallback
Validate before calling
const response = (await cache.tryGet(key, getter, config.cache.routeExpire, false)) as BitgetResponse | undefined;
if (!response) {
throw new Error('Failed to fetch announcements (purge cache key ' + key + ')');
} Type guard
const isBitgetResponse = (r: unknown): r is BitgetResponse =>
typeof r === 'object' && r !== null && (r as any).code === '200'; Try / catch
try {
const response = await cache.tryGet(key, getter, ttl, false);
if (!response) throw new Error('Failed to fetch announcements');
return response;
} catch (e) {
await cache.client.del(key); // purge any stale falsy entry
throw e;
} Prevention
- Ensure the cache.tryGet getter returns the full response object, never undefined.
- On persistent failure, purge the bitget:announcement:* cache keys.
- Treat a falsy cached value as a signal to refresh, not as final.
When it happens
Trigger: cache.tryGet resolves to undefined/null/0 — either a stale falsy cache entry exists for the key 'bitget:announcement:{type}:{pageSize}:{lang}', or the getter returned a falsy value that was cached. The subsequent `response.data.items` access would throw, so the guard converts it to a clear message.
Common situations: A prior bug cached a falsy value with the same key; manual cache corruption; the getter logic changed but old cache entries persist.
Related errors
- Failed to fetch announcements, error code: ' + result?.code
- This path is currently fetching, please come back later!
- Category not found
- Tag not found
- Unhandle asset type: ${a.asset_type}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/56ca60d8c256036c.
Report an issue: GitHub.