{"record":{"id":"f39f10b767583015","repo":"can1357/oh-my-pi","slug":"http-request-failed-status-response-status-ur-f39f10","errorCode":null,"errorMessage":"HTTP request failed. status=${response.status}; url=${url}; body=${responseBody}","messagePattern":"HTTP request failed\\. status=(.+?); url=(.+?); body=(.+?)","errorType":"http","errorClass":"AIError.ProviderHttpError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/registry/oauth/zai.ts","lineNumber":77,"sourceCode":"\t\t\tthrow new AIError.OAuthError(`Z.ai ${operation} failed: ${envelope.msg ?? `code ${String(envelope.code)}`}`, {\n\t\t\t\tkind: \"token-exchange\",\n\t\t\t\tprovider: \"zai\",\n\t\t\t});\n\t\t}\n\t\treturn \"data\" in envelope ? envelope.data : envelope;\n\t}\n\treturn body;\n}\n\nasync function getJson(url: string, headers: Record<string, string>, fetchImpl: FetchImpl): Promise<unknown> {\n\tconst response = await fetchImpl(url, {\n\t\tmethod: \"GET\",\n\t\theaders,\n\t\tsignal: AbortSignal.timeout(30_000),\n\t});\n\tconst responseBody = await response.text();\n\tif (!response.ok) {\n\t\tthrow new AIError.ProviderHttpError(\n\t\t\t`HTTP request failed. status=${response.status}; url=${url}; body=${responseBody}`,\n\t\t\tresponse.status,\n\t\t);\n\t}\n\treturn responseBody.length > 0 ? JSON.parse(responseBody) : undefined;\n}\n\nasync function postJson(\n\turl: string,\n\tbody: Record<string, string | number>,\n\theaders: Record<string, string>,\n\tfetchImpl: FetchImpl,\n): Promise<unknown> {\n\tconst response = await fetchImpl(url, {\n\t\tmethod: \"POST\",\n\t\theaders: { ...headers, \"Content-Type\": \"application/json\" },\n\t\tbody: JSON.stringify(body),\n\t\tsignal: AbortSignal.timeout(30_000),","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/ai/src/registry/oauth/zai.ts#L59-L95","documentation":"getJson performs a GET against a Z.ai business endpoint with a 30s timeout and throws AIError.ProviderHttpError when the HTTP status is not ok, including the status, URL, and raw response body. This is a transport/HTTP-level failure surfaced from the Z.ai REST API.","triggerScenarios":"GET to org/project list or api key copy endpoint returns 401/403/404/429/5xx; the copy endpoint path contains a malformed apiKey; auth headers carry an invalid biz token; network middleboxes return error pages.","commonSituations":"Expired business token causing 401; wrong BIZ_BASE region host; Z.ai API returns 429 under rate limiting; copy endpoint 404 because the key was deleted concurrently.","solutions":["Inspect status and body in the ProviderHttpError: 401/403 → refresh the business token via business login; 404 → verify organizationId/projectId/apiKey; 429/5xx → back off and retry.","Re-authenticate the Z.ai business token and retry the GET.","Confirm the correct regional BIZ_BASE URL for the account.","Wrap calls in retry with exponential backoff for transient 429/5xx statuses."],"exampleFix":"// before\nconst orgs = await getJson(ORGS_URL, auth, fetch);\n// after\nlet orgs;\ntry { orgs = await getJson(ORGS_URL, auth, fetch); }\ncatch (e) {\n  if (e instanceof AIError.ProviderHttpError && (e.status === 429 || e.status >= 500)) { await Bun.sleep(1000); orgs = await getJson(ORGS_URL, auth, fetch); }\n  else throw e;\n}","handlingStrategy":"retry","validationCode":"if (!bizToken || typeof bizToken !== \"string\") throw new Error(\"Refusing GET: missing Z.ai business token\");","typeGuard":null,"tryCatchPattern":"try { return await getJson(url, auth, fetch); }\ncatch (e) {\n  if (e instanceof AIError.ProviderHttpError && (e.status === 429 || e.status >= 500) && attempt < 3) { await Bun.sleep(2 ** attempt * 500); return retry(); }\n  throw e;\n}","preventionTips":["Refresh the business token before it expires","Retry only 429/5xx with backoff; fail fast on 401/403/404","Log status+body from ProviderHttpError for diagnosis","Verify regional endpoint URLs in configuration"],"tags":["zai","http","network","get-request","api-error"],"backgroundTag":"http-request-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}