{"record":{"id":"b75ffe0432596cc4","repo":"koala73/worldmonitor","slug":"cf-radar-traffic-anomalies-api-error-resp-status","errorCode":null,"errorMessage":"CF Radar traffic anomalies API error: ${resp.status}","messagePattern":"CF Radar traffic anomalies API error: (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/seed-internet-outages.mjs","lineNumber":284,"sourceCode":"    dateRangeStart: meta?.dateRange?.[0]?.startTime || '',\n    dateRangeEnd: meta?.dateRange?.[0]?.endTime || '',\n    topTargetLocations,\n    _targetLocationsDegraded: targetSlice.degraded,\n  };\n}\n\n\nasync function fetchTrafficAnomalies(token) {\n  const headers = {\n    'User-Agent': CHROME_UA,\n    ...(token ? { Authorization: `Bearer ${token}` } : {}),\n  };\n\n  const resp = await fetch(`${CF_RADAR_BASE}/radar/traffic_anomalies?dateRange=7d&limit=100`, {\n    headers,\n    signal: AbortSignal.timeout(15_000),\n  });\n  if (!resp.ok) throw new Error(`CF Radar traffic anomalies API error: ${resp.status}`);\n\n  const result = requireRadarResult(await resp.json(), 'traffic anomalies');\n  const raw = requireRadarArray(result, 'trafficAnomalies', 'traffic anomalies');\n\n  const anomalies = raw.map((item) => {\n    const coords = COUNTRY_COORDS[item.locationDetails?.code] || null;\n    return {\n      uuid: item.uuid || '',\n      type: item.type || '',\n      status: item.status || '',\n      startDate: toEpochMs(item.startDate),\n      endDate: toEpochMs(item.endDate),\n      asn: item.asnDetails?.asn ? String(item.asnDetails.asn) : '',\n      asnName: item.asnDetails?.name || '',\n      locationCode: item.locationDetails?.code || '',\n      locationName: item.locationDetails?.name || '',\n      latitude: coords ? coords[0] : 0,\n      longitude: coords ? coords[1] : 0,","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/scripts/seed-internet-outages.mjs#L266-L302","documentation":"fetchTrafficAnomalies calls the Cloudflare Radar traffic_anomalies endpoint (dateRange=7d, limit=100) and throws `CF Radar traffic anomalies API error: ${resp.status}` when the response status is not ok. This is the fatal, non-degradable guard for the traffic-anomalies portion of the internet-outages seed; any non-2xx aborts that dataset. The status code is the only diagnostic detail preserved.","triggerScenarios":"GET /radar/traffic_anomalies?dateRange=7d&limit=100 returns 401/403 (invalid or under-scoped API token), 429 (rate limit), or 5xx (Radar outage), caught by `if (!resp.ok) throw`.","commonSituations":"Token without the traffic-anomalies (Radar) scope; quota exhaustion from repeated 15s-timeout seed runs; Cloudflare-side incident returning 500/503.","solutions":["Curl the exact URL with the seed's headers to see the status and response body directly.","401/403: fix token validity/scope; 429: space out runs or add exponential backoff; 5xx: retry and check Cloudflare status.","Wrap the fetch in a small retry helper (2-3 attempts, backoff) for transient statuses before failing the seed.","If the endpoint is optional to your use case, downgrade to a degraded result like fetchOptionalTargetLocations does instead of throwing."],"exampleFix":"// before\nconst resp = await fetch(url, { headers, signal: AbortSignal.timeout(15_000) });\nif (!resp.ok) throw new Error(`CF Radar traffic anomalies API error: ${resp.status}`);\n// after\nconst resp = await fetch(url, { headers, signal: AbortSignal.timeout(15_000) });\nif (!resp.ok) {\n  if (resp.status === 429 || resp.status >= 500) return retryAfterBackoff(url, headers);\n  throw new Error(`CF Radar traffic anomalies API error: ${resp.status} ${await resp.text().catch(() => '')}`);\n}","handlingStrategy":"retry","validationCode":"const pre = await fetch(`${CF_RADAR_BASE}/radar/traffic_anomalies?dateRange=7d&limit=100`, { headers });\nconsole.log(`traffic_anomalies reachable: ${pre.ok} (${pre.status})`);","typeGuard":null,"tryCatchPattern":"try {\n  const anomalies = await fetchTrafficAnomalies(headers);\n} catch (err) {\n  const status = Number(err.message.match(/(\\d+)$/)?.[1]);\n  if (status === 429 || status >= 500) await retryWithBackoff(() => fetchTrafficAnomalies(headers), 3);\n  else throw err;\n}","preventionTips":["Validate the API token's Radar scope in CI before running seeds.","Apply exponential backoff for 429/5xx instead of immediate failure.","Capture the response body text in the error for faster diagnosis.","Monitor per-hour request counts against Radar quota."],"tags":["http","cloudflare-radar","seed-script","network"],"backgroundTag":"http-error-response","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}