DIYgod/RSSHub · error · Error

Failed to fetch announcements, error code: ' + result?.code

Error message

Failed to fetch announcements, error code: ' + result?.code

What it means

Generic Error thrown inside the cache.tryGet fetcher closure when Bitget's /v1/msg/push/stationLetterNew POST returns a body whose `code` field is not '200'. Because the throw happens inside the async getter, cache.tryGet (called with cacheErrorFlag=false) will NOT cache the failure and the error propagates to the request.

Source

Thrown at lib/routes/bitget/announcement.ts:76

        case 'all':
            reqBody.stationLetterType = '0';
            reqBody.excludeStationLetterType = '00';
            break;

        default:
            throw new Error('Invalid type');
    }

    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 = {

View on GitHub (pinned to bed535e087)

Solutions

  1. Retry shortly — transient Bitget backend errors usually clear; note cache.tryGet already avoids caching the bad result.
  2. Verify the lang parameter is supported (default zh-CN) and languageType/locale headers are well-formed.
  3. If persistent, manually call the Bitget API to read the exact non-200 code and message, then update the route.
  4. Confirm the announcementApiUrl endpoint is still valid (Bitget may have versioned it).

Example fix

// before
if (result?.code !== '200') {
    throw new Error('Failed to fetch announcements, error code: ' + result?.code);
}
// after (include the API message for diagnosis)
if (result?.code !== '200') {
    throw new Error(`Failed to fetch announcements, code: ${result?.code}, msg: ${result?.msg ?? result?.message}`);
}
Defensive patterns

Strategy: retry

Validate before calling

const result = await ofetch<BitgetResponse>(announcementApiUrl, { method:'POST', body: reqBody, headers });
if (!result || result.code !== '200') {
    throw new Error('Failed to fetch announcements, error code: ' + result?.code);
}

Type guard

const isBitgetSuccess = (r: BitgetResponse | undefined): boolean =>
    !!r && r.code === '200' && Array.isArray(r.data?.items);

Try / catch

// cache.tryGet is called with cacheErrorFlag=false, so failures are not cached.
// Wrap to retry transient non-200s a bounded number of times:
let lastErr;
for (let i = 0; i < 3; i++) {
    try { return await fetchOnce(); }
    catch (e) { lastErr = e; await delay(500 * (i + 1)); }
}
throw lastErr;

Prevention

When it happens

Trigger: The POST to the Bitget announcement API succeeds at the HTTP level but the JSON envelope reports a non-success code (e.g. rate-limit, maintenance, invalid languageType, or a changed contract). result?.code !== '200' triggers the throw.

Common situations: Bitget rate-limiting the IP; sending a lang that maps to an unsupported languageType; Bitget changing their response envelope; transient backend errors on Bitget's side.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/cc0479c0c0d0b6eb. Report an issue: GitHub.