DIYgod/RSSHub · error · Error

API error: ${response.message}

Error message

API error: ${response.message}

What it means

Thrown by the Codefather questions route when the upstream `api.codefather.cn` questions-list endpoint returns `code !== 0`. Same envelope convention as the posts route: 0 = success, non-zero = error with `response.message`. The handler hardcodes `{ current: 1, pageSize: 20, sortField, sortOrder: 'descend' }`. Plain `Error`.

Source

Thrown at lib/routes/codefather/questions.ts:51

    const sort = ctx.req.param('sort') || 'new';

    const sortConfig = sort === 'hot' ? { field: 'favourNum', name: '热门' } : { field: 'createTime', name: '最新' };

    const response = await ofetch('https://api.codefather.cn/api/qa/list/page/vo', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: {
            current: 1,
            pageSize: 20,
            sortField: sortConfig.field,
            sortOrder: 'descend',
        },
    });

    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 title = (item.title as string) || '无标题';
        const content = (item.content as string) || '';
        const user = (item.user as Record<string, unknown>) || {};
        const tags = (item.tags as string[]) || [];
        const bestComment = item.bestComment as Record<string, unknown> | undefined;

        // Build description content
        let description = `<div>${content.replaceAll('\n', '<br>')}</div>`;

        // Add best answer
        if (bestComment) {
            const answerUser = (bestComment.user as Record<string, unknown>) || {};
            description += '<hr><h4>💡 最佳回答</h4>';

View on GitHub (pinned to bed535e087)

Solutions

  1. Read `response.message` for the API's stated reason.
  2. Verify `sortConfig.field` against the values the codefather.cn frontend actually sends (network tab).
  3. Retry once for transient backend errors.
  4. If auth-related, the endpoint may now require a token the route does not provide.
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 });
    if (response.code !== 0) {
        throw new Error(`API error: ${response.message}`);
    }
} catch (e) {
    throw new Error(`Codefather questions failed: ${(e as Error).message}`);
}

Prevention

When it happens

Trigger: The `sortConfig.field` value is not accepted by the API, the endpoint is temporarily degraded, or an anonymous request triggers a login-required business error code.

Common situations: Maintainer changed `sortConfig.field` to an unsupported value; the API tightened auth; transient backend failure.

Related errors


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