DIYgod/RSSHub · warning · Error
未能获取热榜数据: ${title}
Error message
未能获取热榜数据: ${title} What it means
Thrown by 煎蛋 (jandan) utils when the hot-list API response's `code` field is not `0`. The route interprets `code === 0` as success (standard Chinese-API convention); any other code means the upstream rejected/failed the request. The message includes the resolved `title` (the ranking variant being fetched) for context.
Source
Thrown at lib/routes/jandan/utils.ts:48
export const handleTopSection = async (rootUrl: string, type: string): Promise<{ title: string; items: DataItem[] }> => {
const apiUrl = `${rootUrl}/api/top/${type}`;
const response = await ofetch(apiUrl);
let title = '热榜';
switch (type) {
case 'pic3days':
title += ' - 3天内无聊图';
break;
case 'pic7days':
title += ' - 7天内无聊图';
break;
default:
title += ' - 4小时热门';
break;
}
if (response.code !== 0) {
throw new Error(`未能获取热榜数据: ${title}`);
}
const items = response.data.map((item) => {
const content = item.content.replaceAll(/img src="(.*?)"/g, (match, src) => match.replace(src, () => src.replace(/^https?:\/\/(\w+)\.moyu\.im/, 'https://$1.sinaimg.cn')));
return {
author: item.author,
title: `${item.author}: ${sanitizeHtml(content, { allowedTags: [], allowedAttributes: {} })}`,
description: content,
pubDate: parseDate(item.date_gmt),
link: `${rootUrl}/t/${item.id}`,
} as DataItem;
});
return { title, items };
};
/**View on GitHub (pinned to bed535e087)
Solutions
- Retry after a short delay — transient upstream errors often clear.
- Clear any cached failed response so the route re-fetches (the response is cached via `cache.tryGet`).
- Verify the upstream API directly (inspect the jandan/moyu endpoint) to see the returned code/message and adjust the route if the API changed.
- If the server IP is blocked, use a proxy.
Example fix
// before: upstream returns { code: -1, msg: 'error' } -> throw
// after: clear cache + retry, or surface the upstream msg for diagnosis
if (response.code !== 0) {
throw new Error(`未能获取热榜数据 (${response.code}): ${response.msg ?? ''} [${title}]`);
} Defensive patterns
Strategy: validation
Validate before calling
if (response.code !== 0) {
throw new Error(`未能获取热榜数据 (${response.code}): ${response.msg ?? 'upstream error'} [${title}]`);
} Type guard
const isOkCode = (r: any): r is {code:0; data:any[]} => r && r.code === 0 && Array.isArray(r.data); Try / catch
try {
const response = await got(apiUrl);
if (response.code !== 0) throw new Error(`jandan upstream code ${response.code}`);
} catch (e) { /* one retry, then surface with context */ throw e; } Prevention
- Cache the successful response (route already uses cache.tryGet) and avoid hammering upstream. Surface the upstream code/msg in the error for diagnosis. Retry once on transient non-zero codes.
When it happens
Trigger: Request to a jandan hot-list route (e.g. `/jandan/pic4hours`, `pic3days`, `pic7days`, etc.) where the upstream moyu.im / jandan API returns `response.code !== 0` — server-side error, invalid ranking type, or upstream maintenance.
Common situations: Upstream API temporarily returns an error code; the ranking-type param was accepted by the route's switch but rejected by the API; upstream IP-blocked the RSSHub server; API schema/version drift.
Related errors
- This path is currently fetching, please come back later!
- Category not found
- Tag not found
- WASM function not available
- Failed to fetch announcements, error code: ' + result?.code
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/d2652dfa30db8ebc.
Report an issue: GitHub.