{"record":{"id":"869128f31937c150","repo":"decolua/9router","slug":"codebuddy-intl-state-error-data-msg-missin","errorCode":null,"errorMessage":"`CodeBuddy Intl state error: ${data.msg || \"missing state/authUrl\"}`","messagePattern":"`CodeBuddy Intl state error: (.+?)`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/oauth/providers/codebuddy-intl.js","lineNumber":25,"sourceCode":"  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,\n        \"X-Requested-With\": \"XMLHttpRequest\",\n        \"X-Domain\": \"www.codebuddy.ai\",\n        \"X-No-Authorization\": \"true\",","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/oauth/providers/codebuddy-intl.js#L7-L43","documentation":"CodeBuddy International returned HTTP 200 but the application envelope is an error: code !== 0 or data.data.state / data.data.authUrl is absent. The API's msg is embedded in the message, defaulting to 'missing state/authUrl'. This is a payload-level rejection, distinct from the transport-level [203].","triggerScenarios":"The intl state endpoint responds 200 with { code: non-zero } or a reshaped payload missing state/authUrl — service degradation returning 200, schema drift in the intl API, or region/policy restrictions reported via msg.","commonSituations":"Intl API response shape changed in an update; temporary server-side condition like 'login busy' or maintenance encoded as code!=0; account restrictions; CDN/edge serving a 200 stub.","solutions":["Read the msg in the message for the API's stated reason.","Dump the full JSON envelope and verify expected keys {code, data:{state, authUrl}}; adjust field access if the schema moved.","Retry the request — application errors here are often transient.","Check for CodeBuddy Intl client updates and sync the provider config."],"exampleFix":"// before\nif (data.code !== 0 || !data.data?.state || !data.data?.authUrl) {\n  throw new Error(`CodeBuddy Intl state error: ${data.msg || \"missing state/authUrl\"}`);\n}\n// after\nif (data.code !== 0 || !data.data?.state || !data.data?.authUrl) {\n  throw new Error(`CodeBuddy Intl state error: ${data.msg || \"missing state/authUrl\"} (code=${data.code}, keys=${Object.keys(data.data || {})})`);\n}","handlingStrategy":"validation","validationCode":"// Validate intl envelope before use\nconst data = await response.json();\nif (data.code !== 0 || !data.data?.state || !data.data?.authUrl) {\n  console.error(\"CodeBuddy Intl envelope:\", JSON.stringify(data).slice(0, 1000));\n}","typeGuard":"function isCodeBuddyIntlStateEnvelope(v) {\n  return !!v && typeof v === \"object\" && v.code === 0 &&\n    typeof v.data === \"object\" && v.data !== null &&\n    typeof v.data.state === \"string\" && v.data.state.length > 0 &&\n    typeof v.data.authUrl === \"string\" && /^https?:\\/\\//.test(v.data.authUrl);\n}","tryCatchPattern":"try {\n  const s = await startCodeBuddyIntlFlow();\n} catch (err) {\n  if (String(err.message).includes(\"CodeBuddy Intl state error\")) {\n    console.error(\"CodeBuddy Intl API rejection:\", err.message);\n    // inspect msg; retry only if it indicates a transient condition\n  } else throw err;\n}","preventionTips":["Capture and store the full envelope on failure to diagnose schema drift.","Gate retries on the msg/code value — some rejections are permanent.","Version-pin the provider config against the intl API you tested against.","Validate URL shape of authUrl before handing it to a browser/opener."],"tags":["oauth","device-flow","api-schema","response-validation"],"backgroundTag":"api-schema-validation-failed","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}