DIYgod/RSSHub · error · Error
API error: ${response.message}
Error message
API error: ${response.message} What it means
Thrown by the Codefather posts route when the upstream JSON API `https://api.codefather.cn/api/post/list/page/vo` returns `code !== 0`. Codefather's convention: `code: 0` = success, any other code is an error and `response.message` carries the Chinese-language reason. The route surfaces that message verbatim. Plain `Error`.
Source
Thrown at lib/routes/codefather/posts.ts:67
pageSize: 20,
sortField: sortConfig.field,
sortOrder: 'descend',
};
if (category && validCategories.has(category)) {
requestBody.category = category;
}
const response = await ofetch('https://api.codefather.cn/api/post/list/page/vo', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: requestBody,
});
if (response.code !== 0) {
throw new Error(`API error: ${response.message}`);
}
const records = response.data?.records || [];
const items = records.map((item: Record<string, unknown>) => {
const content = (item.content as string) || '';
const pictureList = (item.pictureList as string[]) || [];
const user = (item.user as Record<string, unknown>) || {};
const tags = (item.tags as Array<{ tagName: string }>) || [];
// Build description content
let description = `<p>${content.replaceAll('\n', '<br>')}</p>`;
// Add images
if (pictureList.length > 0) {
description += '<div>';
for (const pic of pictureList) {
description += `<img src="${pic}" style="max-width: 100%;" />`;View on GitHub (pinned to bed535e087)
Solutions
- Read the surfaced `response.message` — it is the API's own explanation (often in Chinese).
- Compare the request body against a known-working call captured from codefather.cn in the browser network tab.
- If `category` was supplied, confirm it is a valid category id on the site.
- Retry transient business errors after a short delay.
Defensive patterns
Strategy: try-catch
Type guard
function isCodefatherSuccess(r: unknown): r is { code: 0; data: { records: unknown[] } } {
return typeof r === 'object' && r !== null && (r as any).code === 0;
} Try / catch
try {
const response = await ofetch(url, { method: 'POST', body: requestBody });
if (response.code !== 0) {
throw new Error(`API error: ${response.message}`);
}
} catch (e) {
// network vs. business error
throw new Error(`Codefather posts failed: ${(e as Error).message}`);
} Prevention
- Capture a working request body from codefather.cn's network tab and diff against the route's body.
- Validate `category` against the site's real category ids before adding to `requestBody`.
- Retry once on transient business codes, but treat persistent non-zero codes as an API-contract change.
When it happens
Trigger: Posting a request body the API rejects (malformed category, invalid sorting field, missing required field), server-side validation failure, or an authenticated-only operation attempted anonymously.
Common situations: Passing an unknown `category` value into `requestBody.category`, sending a `sortField` not in the API's whitelist, or the API temporarily returning 5xx-mapped business codes during maintenance.
Related errors
- API error: ${response.message}
- Failed to fetch channel data from Castbox
- Failed to fetch episode list from Castbox
- No posts found for the given IDs
- Invalid API response: ${JSON.stringify(response)}
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/8acd1cb7599cfc03.
Report an issue: GitHub.