{"record":{"id":"bf1f86077f341faf","repo":"jackwener/OpenCLI","slug":"fetch-error-bf1f86","errorCode":"FETCH_ERROR","errorMessage":"HF API error: ${res.status} ${res.statusText}","messagePattern":"HF API error: (.+?) (.+?)","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/hf/top.js","lineNumber":66,"sourceCode":"            return kwargs._footerDate;\n        if (kwargs.period === 'monthly')\n            return getMonthRange();\n        if (kwargs.period === 'weekly')\n            return getWeekRange();\n        return kwargs.date ?? new Date().toISOString().slice(0, 10);\n    },\n    func: async (kwargs) => {\n        const period = String(kwargs.period ?? 'daily');\n        const all = Boolean(kwargs.all);\n        const endpoint = process.env.HF_ENDPOINT?.replace(/\\/+$/, '') || 'https://huggingface.co';\n        if (period === 'weekly' || period === 'monthly') {\n            if (kwargs.date) {\n                throw new CliError('INVALID_ARG', `--date is not supported for ${period} period`, `Omit --date when using --period ${period}`);\n            }\n            const url = `${endpoint}/api/papers?period=${period}`;\n            const res = await fetch(url);\n            if (!res.ok)\n                throw new CliError('FETCH_ERROR', `HF API error: ${res.status} ${res.statusText}`, 'Check HF_ENDPOINT or try again later');\n            const body = await res.json();\n            if (!Array.isArray(body))\n                throw new CliError('FETCH_ERROR', 'Unexpected HF API response', 'Check endpoint');\n            const data = body;\n            const dates = data.map((d) => d.publishedAt).filter(Boolean).sort();\n            if (dates.length > 0) {\n                if (period === 'monthly') {\n                    const d = new Date(dates[0]);\n                    kwargs._footerDate = `${MONTH_ABBR[d.getUTCMonth()]} ${d.getUTCFullYear()}`;\n                }\n                else {\n                    const start = new Date(dates[0]);\n                    const end = new Date(dates[dates.length - 1]);\n                    const sm = MONTH_ABBR[start.getUTCMonth()];\n                    const em = MONTH_ABBR[end.getUTCMonth()];\n                    const sd = start.getUTCDate();\n                    const ed = end.getUTCDate();\n                    kwargs._footerDate = sm === em ? `${sm} ${sd}-${ed}` : `${sm} ${sd}-${em} ${ed}`;","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/top.js#L48-L84","documentation":"A CliError with code FETCH_ERROR thrown when the HF papers endpoint (/api/papers?period=weekly|monthly) returns a non-2xx status. The status code and statusText are surfaced so the caller knows whether it's a client or server problem.","triggerScenarios":"fetch to ${HF_ENDPOINT}/api/papers?period=weekly|monthly returns 4xx/5xx: HF outage, invalid HF_ENDPOINT override, rate limiting, or API changes.","commonSituations":"HF_ENDPOINT misconfigured to a mirror/proxy that doesn't implement /api/papers; HF API downtime; corporate proxy returning 403; typos in the env var value (e.g. missing scheme).","solutions":["Retry later if status is 5xx (HF-side incident)","Check HF_ENDPOINT — unset it or set it to https://huggingface.co","Test the URL directly: curl \"$HF_ENDPOINT/api/papers?period=weekly\"","Fix proxy/firewall blocking if status is 403/502"],"exampleFix":"// before\nexport HF_ENDPOINT=https://mirror.example.com  // doesn't implement /api/papers\n// after\nunset HF_ENDPOINT  # or export HF_ENDPOINT=https://huggingface.co","handlingStrategy":"retry","validationCode":"// verify endpoint health and configuration first\nconst ep = (process.env.HF_ENDPOINT || 'https://huggingface.co').replace(/\\/+$/, '');\nconst health = await fetch(`${ep}/api/papers?period=weekly`).then(r => r.ok).catch(() => false);\nif (!health) console.warn(`HF papers endpoint not reachable at ${ep}`);","typeGuard":null,"tryCatchPattern":"async function fetchPapers(period, tries = 3) {\n  for (let i = 0; ; i++) {\n    try { return await run(['hf', 'top', '--period', period]); }\n    catch (e) {\n      const m = /HTTP (\\d{3})/.exec(String(e.message ?? e));\n      if (!m || Number(m[1]) < 500 || i >= tries - 1) throw e;\n      await new Promise(r => setTimeout(r, 2 ** i * 1000));\n    }\n  }\n}","preventionTips":["Only override HF_ENDPOINT with a mirror that actually implements /api/papers","Include scheme in HF_ENDPOINT (https://...)","Retry with backoff on 5xx; treat 4xx as a config problem","Probe the endpoint with curl before scheduled runs"],"tags":["http","huggingface","api","cli"],"backgroundTag":"http-non-ok-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}