{"record":{"id":"05f6e0813bf8ed4b","repo":"anuraghazra/github-readme-stats","slug":"github-rest-api-error","errorCode":"GITHUB_REST_API_ERROR","errorMessage":"Could not fetch total commits.","messagePattern":"Could not fetch total commits\\.","errorType":"error_code","errorClass":"CustomError","httpStatus":null,"severity":"error","filePath":"src/fetchers/stats.js","lineNumber":207,"sourceCode":" * #92#issuecomment-661026467 and #211 for more information.\n */\nconst totalCommitsFetcher = async (username) => {\n  if (!githubUsernameRegex.test(username)) {\n    logger.log(\"Invalid username provided.\");\n    throw new Error(\"Invalid username provided.\");\n  }\n\n  let res;\n  try {\n    res = await retryer(fetchTotalCommits, { login: username });\n  } catch (err) {\n    logger.log(err);\n    throw new Error(err);\n  }\n\n  const totalCount = res.data.total_count;\n  if (!totalCount || isNaN(totalCount)) {\n    throw new CustomError(\n      \"Could not fetch total commits.\",\n      CustomError.GITHUB_REST_API_ERROR,\n    );\n  }\n  return totalCount;\n};\n\n/**\n * Fetch stats for a given username.\n *\n * @param {string} username GitHub username.\n * @param {boolean} include_all_commits Include all commits.\n * @param {string[]} exclude_repo Repositories to exclude.\n * @param {boolean} include_merged_pull_requests Include merged pull requests.\n * @param {boolean} include_discussions Include discussions.\n * @param {boolean} include_discussions_answers Include discussions answers.\n * @param {number|undefined} commits_year Year to count total commits\n * @returns {Promise<import(\"./types\").StatsData>} Stats data.","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/anuraghazra/github-readme-stats/blob/54a7985aeefda00d5eadb55b80c17c7f976c37d2/src/fetchers/stats.js#L189-L225","documentation":"CustomError(GITHUB_REST_API_ERROR) thrown by totalCommitsFetcher when the REST /search/commits response has no usable total_count (!totalCount || isNaN(totalCount)). The retryer returned a response object, but res.data.total_count is missing, 0, or non-numeric. The secondary message is 'Please try again later' (TRY_AGAIN_LATER), framing it as a transient GitHub REST API issue.","triggerScenarios":"GitHub's /search/commits endpoint returns a payload without total_count (e.g. an error envelope, an empty 200, or a non-JSON body parsed to something unexpected); total_count is literally 0; or the field is present but non-numeric. Because the prior try/catch already handled thrown errors, this is specifically a 'responded but unusable' case.","commonSituations":"GitHub REST API incident/degraded state returning an unusual body; the cloak-preview Accept header no longer being honored after an API change; or a username that legitimately has zero matching commits (total_count === 0 trips the !totalCount guard).","solutions":["Retry after a short delay — the secondary message says 'try again later' and most causes are transient.","Verify GitHub REST API status at https://www.githubstatus.com.","If the user genuinely has 0 commits, consider whether the !totalCount guard (which treats 0 as failure) is appropriate; report upstream if so.","Fall back to include_all_commits=false to use GraphQL contributions instead."],"exampleFix":"// before\n// GET /api/?username=X&include_all_commits=true  -> 'Could not fetch total commits.'\n\n// after (fall back to GraphQL contributions count)\n// GET /api/?username=X","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Fall back to the GraphQL contributions count when the REST total-count path fails.\ntry {\n  stats.totalCommits = await totalCommitsFetcher(username);\n} catch (err) {\n  if (err.type === CustomError.GITHUB_REST_API_ERROR) {\n  // degrade to GraphQL-sourced contributions instead of failing the whole card\n  stats.totalCommits = user.commits.totalCommitContributions;\n  } else throw err;\n}","preventionTips":["Treat GITHUB_REST_API_ERROR as transient — retry once before falling back.","If you don't strictly need all-time commits, leave include_all_commits=false to avoid this path."],"tags":["stats","rest-api","transient","include-all-commits","github-api"],"backgroundTag":null,"analyzedSha":"54a7985aeefda00d5eadb55b80c17c7f976c37d2","analyzedAt":"2026-08-12T23:20:41.776Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}