DIYgod/RSSHub · error · Error
没有获取到内容,可能需要更新解析规则
Error message
没有获取到内容,可能需要更新解析规则
What it means
Thrown by handleCommentSection in the jandan route after it fetched `/api/comment/post/${pageId}?order=desc&page=0` and the response's `code` field is not 0 (Chinese: 'no content obtained, parsing rules may need updating'). Unlike the pageId error, this fires downstream: the page was found but the comment API rejected it.
Source
Thrown at lib/routes/jandan/utils.ts:113
/**
* Handle other sections (问答, 树洞, 随手拍, 女装, 无聊图)
*/
export const handleCommentSection = async (rootUrl: string, category: string): Promise<{ title: string; items: DataItem[] }> => {
const currentUrl = `${rootUrl}/${category}`;
const { pageId, title: pageTitle } = await extractPageMeta(currentUrl);
const title = pageTitle || `煎蛋 - ${category}`;
if (!pageId) {
throw new Error('无法从页面中获取到帖子ID,可能网站结构已变更');
}
const apiUrl = `${rootUrl}/api/comment/post/${pageId}?order=desc&page=0`;
const commentsData = await ofetch(apiUrl);
if (commentsData.code !== 0) {
throw new Error('没有获取到内容,可能需要更新解析规则');
}
const items = commentsData.data.list.map((comment) => {
const content = comment.content.replaceAll(/img src="(.*?)"/g, (match, src) => match.replace(src, () => src.replace(/^https?:\/\/(\w+)\.moyu\.im/, 'https://$1.sinaimg.cn')));
return {
author: comment.author,
title: `${comment.author}: ${sanitizeHtml(content, { allowedTags: [], allowedAttributes: {} })}`,
description: content,
pubDate: parseDate(comment.date_gmt),
link: `${rootUrl}/t/${comment.id}`,
} as DataItem;
});
return { title, items };
};
View on GitHub (pinned to bed535e087)
Solutions
- Bust the `jandan:pageMeta:${url}` cache so a fresh pageId is extracted
- Manually call /api/comment/post/<pageId>?order=desc&page=0 to see the actual code and message returned
- If the API contract changed, update the code check and the data.list mapping in lib/routes/jandan/utils.ts:112-116
- If some categories legitimately return no comments, downgrade to an empty feed instead of throwing
Example fix
// before
if (commentsData.code !== 0) {
throw new Error('没有获取到内容,可能需要更新解析规则');
}
// after
if (commentsData.code !== 0) {
throw new Error(`没有获取到内容 (code=${commentsData.code}, pageId=${pageId}): ${commentsData.message ?? ''}`);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Confirm the comment API will succeed for a given pageId before relying on it
async function commentApiOk(rootUrl: string, pageId: string): Promise<boolean> {
try {
const d = await ofetch(`${rootUrl}/api/comment/post/${pageId}?order=desc&page=0`);
return d?.code === 0;
} catch {
return false;
}
} Type guard
interface JandanCommentResponse { code: number; data?: { list?: unknown[] } }
function isCommentResponse(v: unknown): v is JandanCommentResponse {
return typeof v === 'object' && v !== null && typeof (v as JandanCommentResponse).code === 'number';
} Try / catch
try {
return await handleCommentSection(rootUrl, category);
} catch (e) {
if (e instanceof Error && e.message.includes('没有获取到内容')) {
// pageMeta cache may hold a stale/removed board — clear and retry once
throw new Error('jandan comment API rejected pageId — refresh pageMeta cache and retry');
}
throw e;
} Prevention
- Invalidate pageMeta cache when the comment API returns code!==0
- Treat code!==0 as retryable for transient outages but permanent for removed boards
- Distinguish 'pageId stale' from 'API contract changed' by logging the code value
- Guard against categories that legitimately have no comment thread
When it happens
Trigger: The extracted pageId is valid syntactically but the comments API returns a non-zero code — most often because the pageId resolved from cache is for a board that no longer exists, the API added a new auth/header requirement, or the category slug maps to a page without a comment thread.
Common situations: Stale cached pageMeta pointing at a removed board; API version bump that changed the success-code contract; rate limiting returning code!==0 with HTTP 200; category that legitimately has no comment thread.
Related errors
- 未能获取鱼塘数据
- ${type} ${slug} not found
- this route is empty, please check the original site or <a hr
- Unknown type: ${item.type}
- Comic Not Found - ${name}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/a247bcdd16bef250.
Report an issue: GitHub.