mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-15 20:10:42 +00:00
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
This commit is contained in:
committed by
Josh Lehman
parent
c522154771
commit
dd800fd135
@@ -67,6 +67,10 @@ async function getToken(creds: Credentials): Promise<string> {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user