{"record":{"id":"937510a16b4d234a","repo":"jackwener/OpenCLI","slug":"github-trending-request-failed-http-resp-status","errorCode":null,"errorMessage":"github-trending request failed: HTTP ${resp.status}","messagePattern":"github-trending request failed: HTTP (.+?)","errorType":"error_code","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/github-trending/repos.js","lineNumber":146,"sourceCode":"\n        const language = String(args.language ?? '').trim();\n        const path = language ? `/trending/${encodeURIComponent(language)}` : '/trending';\n        const url = new URL(`https://github.com${path}`);\n        url.searchParams.set('since', since);\n\n        let resp;\n        try {\n            resp = await fetch(url, {\n                headers: {\n                    'User-Agent': 'Mozilla/5.0 (compatible; opencli/github-trending)',\n                    Accept: 'text/html',\n                },\n            });\n        } catch (error) {\n            throw new CommandExecutionError(`github-trending request failed: ${error?.message || error}`);\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`github-trending request failed: HTTP ${resp.status}`);\n        }\n\n        const html = await resp.text();\n        const rows = parseTrendingHtml(html, limit);\n        if (rows.length === 0) {\n            throw new EmptyResultError('github-trending', language\n                ? `no trending repositories for language \"${language}\" (${since})`\n                : `no trending repositories (${since})`);\n        }\n\n        return rows.map((row, index) => ({\n            rank: index + 1,\n            repo: row.repo,\n            description: row.description,\n            language: row.language,\n            stars: row.stars,\n            forks: row.forks,\n            starsSince: row.starsSince,","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/github-trending/repos.js#L128-L164","documentation":"github-trending scrapes the GitHub trending HTML page via fetch and throws this CommandExecutionError when the HTTP response is not ok (e.g. 403, 404, 5xx). It is thrown after the fetch resolves successfully but the response status indicates failure, distinct from network-level fetch exceptions which produce the error?.message variant.","triggerScenarios":"fetch to https://github.com/trending resolves with resp.ok === false — e.g. GitHub returns 403 (rate limit / bot detection), 404 (bad language slug in the URL), or 5xx (GitHub outage).","commonSituations":"Scraping too frequently and hitting GitHub rate limits or abuse detection; passing an invalid language filter that produces a 404 URL; GitHub HTML endpoint temporarily down or blocked from CI/datacenter IPs; corporate proxy returning an error page.","solutions":["Check resp.status in a browser/curl for the same trending URL to identify 403 vs 404 vs 5xx","If 403: slow down request frequency, add/rotate appropriate User-Agent headers, or run from a residential IP","If 404: fix the language argument to a valid GitHub trending language slug (e.g. 'javascript', not 'JavaScript' with spaces)","If 5xx: retry later; check GitHub status page","Wrap the call in try/catch and fall back to a cached or alternate trending source"],"exampleFix":"// before\nconst rows = await runGithubTrending({ language: 'C++' });\n// after\ntry {\n  const rows = await runGithubTrending({ language: 'cpp' });\n} catch (e) {\n  if (String(e.message).includes('HTTP 403')) {\n    await sleep(60_000); // back off on rate limiting\n  }\n  const rows = await getCachedTrending();\n}","handlingStrategy":"try-catch","validationCode":"const resp = await fetch(trendingUrl);\nif (!resp.ok) {\n  throw new Error(`upstream trending HTTP ${resp.status} — fix URL/backoff before calling CLI`);\n}","typeGuard":"function isOkResponse(resp) {\n  return typeof resp === 'object' && resp !== null && resp.ok === true;\n}","tryCatchPattern":"try {\n  const rows = await runGithubTrending({ language, since });\n} catch (e) {\n  const m = /HTTP (\\d{3})/.exec(String(e.message));\n  if (m && m[1] === '403') scheduleBackoffAndRetry();\n  else fallbackToCache();\n}","preventionTips":["Rate-limit trending scrapes and add jitter/backoff","Validate language slugs against known GitHub trending language list","Set a realistic User-Agent to reduce bot-detection 403s","Monitor GitHub status before running scrapes in CI","Cache last successful results as a fallback"],"tags":["http","scraping","network","github"],"backgroundTag":"http-non-2xx-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}