{"record":{"id":"30a7fc5e2be6cb15","repo":"jackwener/OpenCLI","slug":"fetch-error-30a7fc","errorCode":"FETCH_ERROR","errorMessage":"HTTP ${resp.status}","messagePattern":"HTTP \\$\\{resp\\.status\\}","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/google/trends.js","lineNumber":26,"sourceCode":"cli({\n    site: 'google',\n    name: 'trends',\n    access: 'read',\n    description: 'Get Google Trends daily trending searches',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'region', default: 'US', help: 'Region code (e.g. US, CN, JP)' },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of results' },\n    ],\n    columns: ['title', 'traffic', 'date'],\n    func: async (args) => {\n        const limit = Math.max(1, Math.min(Number(args.limit), 100));\n        const region = encodeURIComponent(args.region);\n        const url = `https://trends.google.com/trending/rss?geo=${region}`;\n        const resp = await fetch(url);\n        if (!resp.ok) {\n            throw new CliError('FETCH_ERROR', `HTTP ${resp.status}`, 'Check your network connection or region code');\n        }\n        const xml = await resp.text();\n        const items = parseRssItems(xml, ['title', 'pubDate', 'ht:approx_traffic']);\n        if (!items.length) {\n            throw new CliError('NOT_FOUND', 'No trending data found', 'Try a different region code');\n        }\n        return items.slice(0, limit).map(item => ({\n            title: item['title'],\n            traffic: item['ht:approx_traffic'], // raw string e.g. \"1,000,000+\", no numeric conversion\n            date: item['pubDate'],\n        }));\n    },\n});\n","sourceCodeStart":8,"sourceCodeEnd":40,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/google/trends.js#L8-L40","documentation":"The google trends command fetches https://trends.google.com/trending/rss?geo=<region> and throws this CliError with code FETCH_ERROR when the response is not ok. The hint mentions both the network connection and the region code because Trends rejects invalid geo codes with 4xx statuses.","triggerScenarios":"fetch() to the trending RSS endpoint returns resp.ok === false — invalid/unsupported geo region code (400/404), HTTP 429 from polling too often, 403 bot/consent rejection, or a Google-side 5xx.","commonSituations":"Passing a wrong or lowercase geo code where Trends expects an uppercase ISO country code (e.g. 'us' vs 'US') or an unsupported region; scraping trends in a loop and getting rate-limited; Trends' bot-protection interstitial returning non-200; transient outages.","solutions":["Verify the geo parameter is a valid uppercase ISO 3166-1 country code supported by Google Trends (e.g. US, GB, DE)","If 429, back off and slow the polling frequency or change IP","Retry after a delay for 5xx statuses","Fetch the URL in a browser to confirm whether the region works interactively","Check network/proxy if all regions fail"],"exampleFix":"// before\nconst region = encodeURIComponent(args.region); // 'us'\nconst url = `https://trends.google.com/trending/rss?geo=${region}`;\n// after\nconst region = encodeURIComponent(args.region.toUpperCase()); // 'US'\nif (!/^[A-Z]{2}$/.test(region)) throw new CliError('VALIDATION', 'Invalid region code', 'Use an ISO country code');","handlingStrategy":"validation","validationCode":"// validate region code before invoking\nconst geo = String(args.region || '').toUpperCase();\nif (!/^[A-Z]{2}$/.test(geo)) throw new Error('region must be an ISO 3166-1 alpha-2 code, e.g. US');","typeGuard":"function isValidRegion(region) {\n  return typeof region === 'string' && /^[A-Za-z]{2}$/.test(region);\n}","tryCatchPattern":"try {\n  return await trendsCommand.func(args);\n} catch (e) {\n  if (e.code === 'FETCH_ERROR') {\n    if (e.message.includes('429')) { await sleep(60000); return trendsCommand.func(args); }\n    if (e.message.includes('400') || e.message.includes('404')) throw new Error('Invalid region code');\n  }\n  throw e;\n}","preventionTips":["Always pass uppercase ISO country codes as geo","Rate-limit trending feed polling to avoid 429","Cache trending results briefly instead of refetching","Verify the geo works at trends.google.com in a browser"],"tags":["network","http","google","trends"],"backgroundTag":"http-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}