Skip to content

Commit 199ab99

Browse files
committed
fix(googlechat): throw on non-ok response instead of parsing error body 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.
1 parent 52a02f7 commit 199ab99

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • extensions/googlechat/src

extensions/googlechat/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { GoogleChatCardV2, GoogleChatReaction } from "./types.js";
1212
const CHAT_API_BASE = "https://chat.googleapis.com/v1";
1313
const CHAT_UPLOAD_BASE = "https://chat.googleapis.com/upload/v1";
1414

15-
async function readGoogleChatJsonResponse<T>(response: Response, label: string): Promise<T> {
15+
export async function readGoogleChatJsonResponse<T>(response: Response, label: string): Promise<T> {
1616
if (!response.ok) {
1717
const body = await response.text().catch(() => "");
1818
throw new Error(`${label}: HTTP ${response.status}${body ? ` — ${body.slice(0, 200)}` : ""}`);

0 commit comments

Comments
 (0)