{"record":{"id":"77457a412808dc91","repo":"DIYgod/RSSHub","slug":"error-77457a","errorCode":null,"errorMessage":"无法获取提交数据","messagePattern":"无法获取提交数据","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/gitcode/repos/commits.ts","lineNumber":50,"sourceCode":"    handler,\n};\n\nasync function handler(ctx) {\n    const { owner, repo, branch } = ctx.req.param();\n    // API路径\n    const apiUrl = `https://web-api.gitcode.com/api/v2/projects/${encodeURIComponent(`${owner}/${repo}`)}/repository/commits`;\n\n    const searchParams: Record<string, any> = {\n        per_page: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 100,\n        ref_name: branch,\n    };\n\n    const { data: response } = await got(apiUrl, {\n        searchParams,\n    });\n\n    if (!response || !response.content) {\n        throw new Error('无法获取提交数据');\n    }\n\n    const items = response.content.map((item) => ({\n        title: md.renderInline(item.title),\n        description: md.render(item.message),\n        author: item.author_name,\n        pubDate: parseDate(item.committed_date),\n        guid: item.id,\n        link: `https://gitcode.com/${owner}/${repo}/commit/${item.id}`,\n    }));\n\n    const branchText = branch ? ` (${branch})` : '';\n    return {\n        title: `${owner}/${repo}/${branchText} - 提交记录`,\n        link: `https://gitcode.com/${owner}/${repo}/commits/${branch || ''}`,\n        item: items,\n    };\n}","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/gitcode/repos/commits.ts#L32-L68","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the owner/repo pair is correct and the repository is public on gitcode.com","If specifying a branch, confirm it exists (omitting branch defaults to the main branch)","Check the raw API response by visiting the apiUrl directly in a browser or curl to see what the API returns","If the API schema changed, update the response.content field access to match the new contract"],"exampleFix":"// before\nif (!response || !response.content) {\n    throw new Error('无法获取提交数据');\n}\n\n// after (include diagnostic detail)\nif (!response || !response.content) {\n    throw new Error(`Failed to fetch commit data for ${owner}/${repo}. API response: ${JSON.stringify(response).slice(0, 500)}`);\n}","handlingStrategy":"validation","validationCode":"// Verify the repo exists before calling the commits API\nconst repoCheckUrl = `https://gitcode.com/${owner}/${repo}`;\ntry {\n    await got.head(repoCheckUrl);\n} catch {\n    throw new InvalidParameterError(`Repository ${owner}/${repo} not found on Gitcode`);\n}","typeGuard":"function hasCommitsData(response: unknown): response is { content: Array<{ id: string; title: string; message: string }> } {\n    return typeof response === 'object' && response !== null && Array.isArray((response as any).content);\n}","tryCatchPattern":null,"preventionTips":["Verify owner/repo exist on gitcode.com before subscribing","Omit the branch parameter to use the default branch","Test the API URL directly to confirm the response shape"],"tags":["api","validation","git","third-party-api"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}