DIYgod/RSSHub · error · Error

无法获取提交数据

Error message

无法获取提交数据

What it means

Thrown by the Gitcode commits route when the Gitcode web API response is falsy or lacks a 'content' property. The route calls https://web-api.gitcode.com/api/v2/projects/{owner}%2F{repo}/repository/commits and expects response.content to be an array of commit objects. If the API returns an error object, empty response, or a different shape, this guard fires.

Source

Thrown at lib/routes/gitcode/repos/commits.ts:50

    handler,
};

async function handler(ctx) {
    const { owner, repo, branch } = ctx.req.param();
    // API路径
    const apiUrl = `https://web-api.gitcode.com/api/v2/projects/${encodeURIComponent(`${owner}/${repo}`)}/repository/commits`;

    const searchParams: Record<string, any> = {
        per_page: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 100,
        ref_name: branch,
    };

    const { data: response } = await got(apiUrl, {
        searchParams,
    });

    if (!response || !response.content) {
        throw new Error('无法获取提交数据');
    }

    const items = response.content.map((item) => ({
        title: md.renderInline(item.title),
        description: md.render(item.message),
        author: item.author_name,
        pubDate: parseDate(item.committed_date),
        guid: item.id,
        link: `https://gitcode.com/${owner}/${repo}/commit/${item.id}`,
    }));

    const branchText = branch ? ` (${branch})` : '';
    return {
        title: `${owner}/${repo}/${branchText} - 提交记录`,
        link: `https://gitcode.com/${owner}/${repo}/commits/${branch || ''}`,
        item: items,
    };
}

View on GitHub (pinned to bed535e087)

Solutions

  1. Verify the owner/repo pair is correct and the repository is public on gitcode.com
  2. If specifying a branch, confirm it exists (omitting branch defaults to the main branch)
  3. Check the raw API response by visiting the apiUrl directly in a browser or curl to see what the API returns
  4. If the API schema changed, update the response.content field access to match the new contract

Example fix

// before
if (!response || !response.content) {
    throw new Error('无法获取提交数据');
}

// after (include diagnostic detail)
if (!response || !response.content) {
    throw new Error(`Failed to fetch commit data for ${owner}/${repo}. API response: ${JSON.stringify(response).slice(0, 500)}`);
}
Defensive patterns

Strategy: validation

Validate before calling

// Verify the repo exists before calling the commits API
const repoCheckUrl = `https://gitcode.com/${owner}/${repo}`;
try {
    await got.head(repoCheckUrl);
} catch {
    throw new InvalidParameterError(`Repository ${owner}/${repo} not found on Gitcode`);
}

Type guard

function hasCommitsData(response: unknown): response is { content: Array<{ id: string; title: string; message: string }> } {
    return typeof response === 'object' && response !== null && Array.isArray((response as any).content);
}

Prevention

When it happens

Trigger: The Gitcode API returns a non-standard response — typically when the owner/repo path doesn't exist, the branch name is invalid, the API endpoint changed, or the API is rate-limiting. The guard checks both the response object itself and its 'content' field.

Common situations: Typo in owner or repo name; specifying a branch that doesn't exist; the Gitcode API changed its response schema between versions; the repo is private or has been deleted.

Related errors


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