{"record":{"id":"27c6381b6a829a70","repo":"affaan-m/ECC","slug":"github-graphql-request-failed-response-status","errorCode":null,"errorMessage":"GitHub GraphQL request failed (${response.status})","messagePattern":"GitHub GraphQL request failed \\((.+?)\\)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/discord/release-announce.mjs","lineNumber":35,"sourceCode":"const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));\n\nasync function request(url, options = {}, attempts = 3) {\n  for (let attempt = 1; attempt <= attempts; attempt += 1) {\n    const response = await fetch(url, options);\n    if (response.status !== 429 || attempt === attempts) return response;\n    const data = await response.json().catch(() => ({}));\n    await sleep(Math.min(Number(data.retry_after || 1) * 1000 + 250, 10_000));\n  }\n  throw new Error('request retry budget exhausted');\n}\n\nasync function githubGraphql(query, variables) {\n  const response = await request('https://api.github.com/graphql', {\n    method: 'POST',\n    headers: { Authorization: `Bearer ${env.GITHUB_TOKEN}`, 'Content-Type': 'application/json' },\n    body: JSON.stringify({ query, variables }),\n  });\n  if (!response.ok) throw new Error(`GitHub GraphQL request failed (${response.status})`);\n  const payload = await response.json();\n  if (payload.errors) throw new Error('GitHub GraphQL returned errors');\n  return payload.data;\n}\n\nasync function releaseFromGitHub() {\n  const [owner, repo] = env.GITHUB_REPOSITORY.split('/');\n  const tag = env.RELEASE_TAG || env.GITHUB_REF_NAME;\n  const response = await request(`https://api.github.com/repos/${owner}/${repo}/releases/tags/${encodeURIComponent(tag)}`, {\n    headers: { Authorization: `Bearer ${env.GITHUB_TOKEN}`, Accept: 'application/vnd.github+json' },\n  });\n  if (!response.ok) throw new Error(`release lookup failed (${response.status})`);\n  return response.json();\n}\n\nasync function createOrFindReleaseDiscussion() {\n  const release = await releaseFromGitHub();\n  const [owner, name] = env.GITHUB_REPOSITORY.split('/');","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/discord/release-announce.mjs#L17-L53","documentation":"githubGraphql wraps the GitHub GraphQL API call and throws a templated error when the HTTP response is not ok, embedding the status code (e.g. 401, 403, 502). GraphQL-level errors returned inside a 200 response are handled separately ('GitHub GraphQL returned errors'); this error specifically means the transport request itself failed.","triggerScenarios":"GITHUB_TOKEN is missing/invalid/expired (401), the token lacks the Discussions read scope or repo access (403), GitHub is returning 5xx during an incident, or request() hit a final 429 that propagates through as a non-ok response.","commonSituations":"Fine-grained PAT without Discussions permission; classic token without the 'repo' scope on a private repo; org token with SSO not authorized; GitHub status degradation; workflow using GITHUB_TOKEN on an event where discussions are inaccessible.","solutions":["Check GITHUB_TOKEN is set, unexpired, and authorized for the target repo; print only the response.status to diagnose which case you have.","For a classic PAT, grant the 'repo' scope; for a fine-grained PAT, enable repository access plus read access to Discussions and Metadata.","If the token is org-scoped, complete SAML/SSO authorization for the token.","Check https://www.githubstatus.com for ongoing API incidents and retry with backoff for 5xx responses.","Verify the endpoint is api.github.com/graphql and the Authorization header format 'Bearer <token>' is intact."],"exampleFix":"// before\nheaders: { Authorization: `Bearer ${env.GITHUB_TOKEN}`, ... }\n// after (fail fast with a clear message when the token is absent)\nif (!env.GITHUB_TOKEN) throw new Error('GITHUB_TOKEN is not set; cannot query GitHub GraphQL');\nheaders: { Authorization: `Bearer ${env.GITHUB_TOKEN}`, ... }","handlingStrategy":"try-catch","validationCode":"function hasGitHubToken() {\n  return typeof process.env.GITHUB_TOKEN === 'string' && process.env.GITHUB_TOKEN.trim().length > 0;\n}\nif (!hasGitHubToken()) throw new Error('GITHUB_TOKEN is required before calling githubGraphql');","typeGuard":null,"tryCatchPattern":"try {\n  const data = await githubGraphql(query, variables);\n} catch (err) {\n  const m = err.message.match(/GitHub GraphQL request failed \\((\\d+)\\)/);\n  if (m) {\n    const status = Number(m[1]);\n    if (status === 401 || status === 403) console.error('Check GITHUB_TOKEN validity, scopes, and SSO authorization');\n    else if (status >= 500) console.error('GitHub-side error; retry with backoff');\n  }\n  throw err;\n}","preventionTips":["Validate the token's scopes (repo, or Discussions read on fine-grained PATs) before the run.","Authorize org tokens via SAML SSO.","Monitor githubstatus.com and add backoff for 5xx responses.","Log only the status code, never the token, when diagnosing failures."],"tags":["network","github","graphql","authentication"],"backgroundTag":"http-error-response","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}