fix(googlechat): throw on non-ok response instead of parsing error body as success#96646
fix(googlechat): throw on non-ok response instead of parsing error body as success#96646ajwan8998 wants to merge 2 commits into
Conversation
…dy as success When the Google Chat API returns 4xx/5xx with a JSON error body, response.json() succeeds and the error gets parsed as the success type, hiding the actual error status and message from callers. Add response.ok check before response.json() so HTTP errors throw with status code and response body instead of silently masquerading as success.
…dy as success When the Google Chat API returns 4xx/5xx with a JSON error body, response.json() parses the error as the success type T, hiding the HTTP status code and error message. The caller sees a type-valid success response where expected fields are undefined. Add response.ok check before response.json() so HTTP errors throw with status code and response body. Export readGoogleChatJsonResponse for reuse.
|
Thanks for the context here. I did a careful shell check against current Close: current main and v2026.6.10 already reject non-ok Google Chat responses in withGoogleChatResponse before JSON parsing, so this PR is redundant and would add duplicate error handling. So I’m closing this as already implemented rather than keeping a duplicate issue open. Review detailsBest possible solution: Keep the existing wrapper-level guard as the canonical Google Chat response contract and avoid adding a second parser-level check/export. Do we have a high-confidence way to reproduce the issue? No failing current-main repro: the send/upload paths call withGoogleChatResponse, which throws on !response.ok before JSON parsing. The PR's synthetic helper proof does not exercise that shipped path. Is this the best way to solve the issue? No. The requested behavior is already solved at the wrapper layer; adding the same guard to the parser is duplicate and less maintainable than keeping one canonical response boundary. Security review: Security review cleared: The diff only changes local Google Chat response handling and does not touch dependencies, workflows, secrets, package metadata, or broader security boundaries. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 643410c1f3c0; fix evidence: release v2026.6.10, commit aa69b12d0086. |
|
ClawSweeper applied the proposed close for this PR.
|
What Problem This Solves
The
readGoogleChatJsonResponsehelper inextensions/googlechat/src/api.tsis used by every Google Chat API call to parse JSON responses. It callsresponse.json()without checkingresponse.okfirst. When the Google Chat API returns a 4xx/5xx status with a JSON error body (e.g.{"error":{"message":"Invalid credentials","code":401}}),response.json()succeeds — it parses the error payload as the success typeT. The caller receives a type-valid "success" response where the actual data is the error object.The downstream impact: a caller processing a 401 response sees
result.message → undefined(because the response shape is{error: ...}not{message: ...}) and has no way to distinguish "API returned a success" from "API returned an error but it got parsed as success." The actual error details ({"message":"Invalid credentials"}) are silently embedded in the payload without any signal that an error occurred.This pattern affects all callers of
withGoogleChatResponse— send, upload, and any future Google Chat API operations. Every Google Chat API error today gets silently swallowed and replaced with confusingundefinedvalues at the call site.Changes
extensions/googlechat/src/api.ts: addresponse.okcheck beforeresponse.json()inreadGoogleChatJsonResponse. On non-ok responses, read the response body text and throw with HTTP status code + body so callers receive a clear error instead of a silently parsed error payload. Export the function for reuse.Real behavior proof
readGoogleChatJsonResponse(exported fromextensions/googlechat/src/api.ts, tested vianpx tsx -ewith realResponseobjects).readGoogleChatJsonResponsewith (1) a 401 response carrying an error JSON body, (2) a 200 OK response carrying a success payload.Evidence
What was not tested: End-to-end with a real Google Chat API (requires credentials).
This is the first PR in a response-ok-check campaign across extensions that call
response.json()without verifying the HTTP status first. The same pattern exists in ~30 other extensions (firecrawl, feishu, elevenlabs, ollama, openai, etc.) and will be addressed in follow-up PRs.