{"record":{"id":"95245e3eee49b000","repo":"decolua/9router","slug":"device-code-request-failed-error","errorCode":null,"errorMessage":"`Device code request failed: ${error}`","messagePattern":"`Device code request failed: (.+?)`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/oauth/providers/github.js","lineNumber":21,"sourceCode":"const github = {\n  config: GITHUB_CONFIG,\n  flowType: \"device_code\",\n  requestDeviceCode: async (config) => {\n    const response = await fetch(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: config.clientId,\n        scope: config.scopes,\n      }),\n    });\n\n    if (!response.ok) {\n      const error = await response.text();\n      throw new Error(`Device code request failed: ${error}`);\n    }\n\n    return await response.json();\n  },\n  pollToken: async (config, deviceCode) => {\n    const response = await fetch(config.tokenUrl, {\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: config.clientId,\n        device_code: deviceCode,\n        grant_type: \"urn:ietf:params:oauth:grant-type:device_code\",\n      }),\n    });\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/lib/oauth/providers/github.js#L3-L39","documentation":"GitHub device-flow step 1: the POST to GitHub's device/code endpoint (client_id + scopes) returned a non-2xx status, and the body text is thrown. Without a device_code the polling loop can never start, so GitHub login aborts immediately.","triggerScenarios":"Calling startDeviceFlow for github when the https://github.com/login/device/code endpoint replies !response.ok — 404 (endpoint moved/blocked), 422 bad client_id or malformed scope string, 403 via proxy, or 5xx GitHub incident.","commonSituations":"Wrong/revoked GitHub OAuth app client_id; scopes joined incorrectly (spaces vs commas causing 422); corporate proxy or offline machine; GitHub status incident; DNS blocking github.com.","solutions":["Read the body: 422 usually means bad client_id or scope format; fix config accordingly.","Verify the GitHub OAuth app's client_id is valid and the app is not suspended.","Test reachability: curl -X POST https://github.com/login/device/code.","Check GitHub status / retry with backoff if the body shows 5xx."],"exampleFix":"// before\nif (!response.ok) {\n  const error = await response.text();\n  throw new Error(`Device code request failed: ${error}`);\n}\n// after\nif (!response.ok) {\n  const error = await response.text();\n  throw new Error(`Device code request failed (HTTP ${response.status}): ${error}`);\n}","handlingStrategy":"validation","validationCode":"// Validate inputs GitHub requires before the device-code request\nif (!config.clientId) throw new Error(\"GitHub OAuth client_id missing\");\nif (!/^([a-z0-9:-]+,?)+$/i.test(config.scopes || \"\")) throw new Error(\"GitHub scopes malformed — use comma/space separated scope names\");","typeGuard":"function hasValidDeviceCodeResponse(v) {\n  return !!v && typeof v === \"object\" &&\n    typeof v.device_code === \"string\" &&\n    typeof v.user_code === \"string\" &&\n    typeof v.verification_uri === \"string\";\n}","tryCatchPattern":"try {\n  const dc = await githubProvider.startDeviceFlow();\n} catch (err) {\n  if (String(err.message).includes(\"Device code request failed\")) {\n    if (responseWas(422)) console.error(\"Bad client_id or scope format for GitHub\");\n    else await retryWithBackoff(() => githubProvider.startDeviceFlow(), { retries: 2 });\n  } else throw err;\n}","preventionTips":["Confirm the GitHub OAuth app client_id is valid and the app is active.","Format scopes the way GitHub expects (space- or comma-separated, no URL encoding surprises).","Pre-check github.com reachability when behind corporate proxies.","Watch GitHub status for incidents before blaming local config."],"tags":["oauth","device-flow","github","http-error"],"backgroundTag":"oauth-device-flow-request-failed","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}