{"record":{"id":"b84ba4ead34dab68","repo":"decolua/9router","slug":"failed-to-get-device-code-error","errorCode":null,"errorMessage":"Failed to get device code: ${error}","messagePattern":"Failed to get device code: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/oauth/services/github.js","lineNumber":32,"sourceCode":"  /**\n   * Get device code for GitHub authentication\n   */\n  async getDeviceCode() {\n    const response = await fetch(`${GITHUB_CONFIG.deviceCodeUrl}`, {\n      method: \"POST\",\n      headers: {\n        \"Content-Type\": \"application/x-www-form-urlencoded\",\n        Accept: \"application/json\",\n      },\n      body: new URLSearchParams({\n        client_id: GITHUB_CONFIG.clientId,\n        scope: GITHUB_CONFIG.scopes,\n      }),\n    });\n\n    if (!response.ok) {\n      const error = await response.text();\n      throw new Error(`Failed to get device code: ${error}`);\n    }\n\n    return await response.json();\n  }\n\n  /**\n   * Poll for access token using device code\n   */\n  async pollAccessToken(deviceCode, verificationUri, userCode, interval = 5000) {\n    const spinner = createSpinner(\"Waiting for GitHub authentication...\").start();\n    \n    // Show user code and verification URL\n    console.log(`\\nPlease visit: ${verificationUri}`);\n    console.log(`Enter code: ${userCode}\\n`);\n    \n    // Open browser automatically\n    try {\n      const open = (await import(\"open\")).default;","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/oauth/services/github.js#L14-L50","documentation":"GitHubService.getDeviceCode() POSTs to GitHub's device-flow endpoint (https://github.com/login/device/code) requesting a device code. If GitHub responds with a non-OK status, the raw response body is embedded into `Failed to get device code: ${error}` and thrown. This is the very first network step of GitHub device authentication, so it means GitHub rejected the device-code request itself.","triggerScenarios":"The POST to GITHUB_CONFIG.deviceCodeUrl returns non-2xx — e.g. a bad/rotated client_id (GitHub returns 404 or 401), a network/proxy block on github.com, or an HTML error page from a captive portal or corporate proxy embedded in the message.","commonSituations":"GITHUB_CONFIG.clientId no longer matches a valid GitHub OAuth app (client revoked/rotated); corporate firewall or proxy intercepting github.com; offline machine or DNS failure so the fetch hits an error page.","solutions":["Check internet/proxy connectivity to github.com (curl -i https://github.com/login/device/code) — fix VPN/proxy/DNS if unreachable.","Verify GITHUB_CONFIG.clientId in src/lib/oauth/constants/oauth.js matches a still-valid GitHub OAuth app's client ID.","Update the CLI/library version if the hardcoded client_id has been revoked by upstream.","Retry later if GitHub is having an incident (githubstatus.com)."],"exampleFix":"// before\nif (!response.ok) {\n  const error = await response.text();\n  throw new Error(`Failed to get device code: ${error}`);\n}\n// after\nif (!response.ok) {\n  const error = await response.text();\n  throw new Error(`Failed to get device code (HTTP ${response.status}): ${error}`);\n}","handlingStrategy":"retry","validationCode":"async function assertGitHubReachable() {\n  const res = await fetch('https://github.com', { method: 'HEAD' }).catch(() => null);\n  if (!res) throw new Error('github.com unreachable — check network/VPN/proxy before starting device auth');\n}","typeGuard":"function isDeviceCodeResponse(data) {\n  return data !== null && typeof data === 'object' && typeof data.device_code === 'string' && typeof data.user_code === 'string';\n}","tryCatchPattern":"try {\n  const deviceResponse = await service.getDeviceCode();\n} catch (err) {\n  if (err.message.startsWith('Failed to get device code')) {\n    console.error('GitHub device-code request failed — verify connectivity to github.com and that the OAuth app client_id is valid.');\n  }\n  throw err;\n}","preventionTips":["Pre-flight check connectivity to github.com (especially behind corporate proxies/VPNs).","Keep the CLI updated so the bundled GitHub OAuth client_id stays valid.","Apply retry with backoff on this first request — transient network blips are common.","Check githubstatus.com before bulk/auth automation runs."],"tags":["network","http","oauth","github"],"backgroundTag":"http-request-failed","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}