{"record":{"id":"0c2dfe5a67095ebd","repo":"can1357/oh-my-pi","slug":"gemini-cloud-code-api-error-status-errorte","errorCode":null,"errorMessage":"Gemini Cloud Code API error (${status}): ${errorText}","messagePattern":"Gemini Cloud Code API error \\((.+?)\\): (.+?)","errorType":"http","errorClass":"SearchProviderError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/web/search/providers/gemini.ts","lineNumber":525,"sourceCode":"\t\t\t\tif (!isLastEndpoint) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t} catch (error) {\n\t\t\tif (isLastEndpoint) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (!response?.ok) {\n\t\tconst rawErrorText = response ? await response.text() : \"Network error\";\n\t\tconst errorText = auth.accessToken ? rawErrorText.split(auth.accessToken).join(\"[redacted]\") : rawErrorText;\n\t\tconst status = response?.status ?? 502;\n\t\tconst classified = classifyProviderHttpError(\"gemini\", status, errorText);\n\t\tif (classified) throw classified;\n\t\tthrow new SearchProviderError(\"gemini\", `Gemini Cloud Code API error (${status}): ${errorText}`, status);\n\t}\n\n\tif (!response.body) {\n\t\tthrow new SearchProviderError(\"gemini\", \"Gemini API returned no response body\", 500);\n\t}\n\n\treturn finalizeGeminiSearchResult(await parseGeminiSearchStream(response.body, model), fetchImpl, signal);\n}\n\nasync function callGeminiDeveloperSearch(\n\tapiKey: string,\n\tendpoint: GeminiDeveloperEndpoint,\n\tmodel: string,\n\tquery: string,\n\tsystemPrompt: string | undefined,\n\tmaxOutputTokens: number | undefined,\n\ttemperature: number | undefined,\n\ttoolParams: GeminiToolParams,","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/web/search/providers/gemini.ts#L507-L543","documentation":"callGeminiSearch() (Cloud Code Assist path) throws this when the Gemini HTTP response is missing or not ok and no more specific classified error applied. The message includes the HTTP status and the raw error body, with the OAuth access token redacted from the text. If there was no response at all (network failure), it reports status 502 with 'Network error'.","triggerScenarios":"Non-OK HTTP status from the Gemini Cloud Code endpoint (401/403 expired OAuth token, 429 quota, 5xx outages), or a fetch that threw/returned no response yielding the 502 'Network error' variant.","commonSituations":"Expired Google Cloud OAuth access tokens, project not provisioned for Code Assist API, quota exhaustion, corporate proxy breaking TLS, or Google-side incidents.","solutions":["Read the embedded status and errorText — 401/403 means re-authenticate (refresh Google Cloud credentials / re-run the login flow), 429 means back off, 5xx means retry later","Re-authenticate: refresh or regenerate the access token used for the Cloud Code Assist API","Check network connectivity/proxy settings if the message shows the 502 'Network error' variant","Retry with exponential backoff for transient statuses (429, 500, 503)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Detect an expired token before searching:\nfunction isTokenExpired(auth: { accessToken?: string; expiresAt?: number }): boolean {\n  return !auth.accessToken || (auth.expiresAt !== undefined && Date.now() >= auth.expiresAt);\n}\nif (isTokenExpired(auth)) await refreshAccessToken();","typeGuard":null,"tryCatchPattern":"import { SearchProviderError } from \"...\";\ntry {\n  results = await searchGemini(query);\n} catch (err) {\n  if (err instanceof SearchProviderError && (err.status === 401 || err.status === 403)) {\n    await refreshGoogleAuth();\n    results = await searchGemini(query);\n  } else if (err instanceof SearchProviderError && (err.status === 429 || err.status >= 500)) {\n    await Bun.sleep(backoffMs);\n    results = await searchGemini(query);\n  } else throw err;\n}","preventionTips":["Refresh Google Cloud OAuth tokens proactively before expiry","Apply exponential backoff on 429/5xx statuses","Redact access tokens when logging error bodies (the library already does this — keep it in your own logs too)","Verify project provisioning for the Cloud Code Assist API before rollout"],"tags":["network","http-error","authentication","gemini"],"backgroundTag":"http-api-error","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}