From dd800fd13596dbcea3093854951f668dc339d03a Mon Sep 17 00:00:00 2001 From: SidQin-cyber Date: Thu, 5 Mar 2026 14:56:03 +0800 Subject: [PATCH] fix(feishu): check response.ok before calling response.json() in streaming card When the Feishu API returns a non-2xx response (e.g. 500 internal error), the body may be HTML or plain text instead of JSON, causing response.json() to throw a JSON parse error. This obscures the real HTTP error. Now checks response.ok and throws with the HTTP status before attempting JSON parsing, in both the token acquisition and card creation paths. Made-with: Cursor --- extensions/feishu/src/streaming-card.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extensions/feishu/src/streaming-card.ts b/extensions/feishu/src/streaming-card.ts index 45db480d360..856c3c2fecd 100644 --- a/extensions/feishu/src/streaming-card.ts +++ b/extensions/feishu/src/streaming-card.ts @@ -67,6 +67,10 @@ async function getToken(creds: Credentials): Promise { policy: { allowedHostnames: resolveAllowedHostnames(creds.domain) }, auditContext: "feishu.streaming-card.token", }); + if (!response.ok) { + await release(); + throw new Error(`Token request failed with HTTP ${response.status}`); + } const data = (await response.json()) as { code: number; msg: string; @@ -198,6 +202,10 @@ export class FeishuStreamingSession { policy: { allowedHostnames: resolveAllowedHostnames(this.creds.domain) }, auditContext: "feishu.streaming-card.create", }); + if (!createRes.ok) { + await releaseCreate(); + throw new Error(`Create card request failed with HTTP ${createRes.status}`); + } const createData = (await createRes.json()) as { code: number; msg: string;