{"record":{"id":"df409b20b2962cf9","repo":"decolua/9router","slug":"codebuddy-intl-state-request-failed-await-resp","errorCode":null,"errorMessage":"`CodeBuddy Intl state request failed: ${await response.text()}`","messagePattern":"`CodeBuddy Intl state request failed: (.+?)`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/oauth/providers/codebuddy-intl.js","lineNumber":22,"sourceCode":"const codebuddyIntl = {\n  config: CODEBUDDY_INTL_CONFIG,\n  flowType: \"device_code\",\n  requestDeviceCode: async (config) => {\n    const response = await fetch(`${config.stateUrl}?platform=${config.platform}`, {\n      method: \"POST\",\n      headers: {\n        \"Content-Type\": \"application/json\",\n        Accept: \"application/json\",\n        \"User-Agent\": config.userAgent,\n        \"X-Requested-With\": \"XMLHttpRequest\",\n        \"X-Domain\": \"www.codebuddy.ai\",\n        \"X-No-Authorization\": \"true\",\n        \"X-No-User-Id\": \"true\",\n        \"X-Product\": \"SaaS\",\n      },\n      body: \"{}\",\n    });\n    if (!response.ok) throw new Error(`CodeBuddy Intl state request failed: ${await response.text()}`);\n    const data = await response.json();\n    if (data.code !== 0 || !data.data?.state || !data.data?.authUrl) {\n      throw new Error(`CodeBuddy Intl state error: ${data.msg || \"missing state/authUrl\"}`);\n    }\n    return {\n      device_code: data.data.state,\n      verification_uri: data.data.authUrl,\n      user_code: \"\",\n      interval: config.pollInterval / 1000,\n      _isCodeBuddy: true,\n    };\n  },\n  pollToken: async (config, deviceCode) => {\n    const response = await fetch(`${config.tokenUrl}?state=${encodeURIComponent(deviceCode)}`, {\n      method: \"GET\",\n      headers: {\n        Accept: \"application/json\",\n        \"User-Agent\": config.userAgent,","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/oauth/providers/codebuddy-intl.js#L4-L40","documentation":"CodeBuddy International device-flow bootstrap: the POST requesting device 'state' returned a non-2xx HTTP status, and the raw body text is thrown inside this Error. Same mechanism as the CN variant [201] but against the intl endpoint; it aborts the device flow before polling begins.","triggerScenarios":"Calling the codebuddy-intl startDeviceFlow when its state endpoint responds !response.ok — endpoint outage, 404 after an API change, proxy/firewall block, or rejection of the anonymous SaaS headers with body '{}'.","commonSituations":"Intl endpoint temporarily down or geo-restricted; corporate proxy stripping custom X-* headers; stale base URL after a provider-side migration; DNS/TLS failure surfacing as a gateway error page.","solutions":["Check the thrown body text for HTTP status clues (404 vs 403 vs 5xx).","Verify reachability of the CodeBuddy Intl base URL from this machine (curl / browser).","Ensure the proxy allows the X-No-Authorization / X-No-User-Id / X-Product headers through.","Update the provider's stateUrl if the intl API was relocated."],"exampleFix":"// before\nif (!response.ok) throw new Error(`CodeBuddy Intl state request failed: ${await response.text()}`);\n// after\nif (!response.ok) {\n  const t = await response.text();\n  throw new Error(`CodeBuddy Intl state request failed (HTTP ${response.status}): ${t.slice(0, 500)}`);\n}","handlingStrategy":"retry","validationCode":"// Precheck intl endpoint reachability\nconst reachable = await fetch(config.stateUrl, { method: \"OPTIONS\" })\n  .then(r => r.status < 500).catch(() => false);\nif (!reachable) throw new Error(\"CodeBuddy Intl state endpoint unreachable\");","typeGuard":"function hasValidDeviceState(data) {\n  return !!data && typeof data === \"object\" &&\n    data.code === 0 && typeof data.data?.state === \"string\" &&\n    typeof data.data?.authUrl === \"string\";\n}","tryCatchPattern":"try {\n  const s = await startCodeBuddyIntlFlow();\n} catch (err) {\n  if (String(err.message).includes(\"CodeBuddy Intl state request failed\")) {\n    await retryWithBackoff(() => startCodeBuddyIntlFlow(), { retries: 3, baseMs: 1000 });\n  } else throw err;\n}","preventionTips":["Verify outbound access to the Intl endpoint (geo/proxy) before shipping the flow.","Ensure custom X-* headers survive your proxy (some strip unknown headers).","Use exponential backoff on non-2xx instead of immediate hard failure.","Keep the intl base URL configurable so endpoint migrations need no code change."],"tags":["oauth","device-flow","http-error","network"],"backgroundTag":"oauth-device-flow-request-failed","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}