diff --git a/packages/sdk/js/src/gen/client/client.gen.ts b/packages/sdk/js/src/gen/client/client.gen.ts index 34a8d0bece..c5b4760b74 100644 --- a/packages/sdk/js/src/gen/client/client.gen.ts +++ b/packages/sdk/js/src/gen/client/client.gen.ts @@ -114,10 +114,29 @@ export const createClient = (config: Config = {}): Client => { case "arrayBuffer": case "blob": case "formData": - case "json": case "text": data = await response[parseAs]() break + // altimate_change start — upstream_fix: guard JSON parse against non-JSON (HTML) response bodies + // "json" is split out of the fall-through group above so its parse can be guarded: a 200 + // whose body is an HTML error page from a proxy/gateway/CDN otherwise crashes with a raw + // "JSON Parse error: Unrecognized token '<'". The body is read OUTSIDE the guard so a + // network/body-read failure (socket reset, abort) keeps its own error; only an actual + // JSON syntax failure gets the actionable message (mirrors the v2 client). + case "json": { + const text = await response.text() + try { + data = text ? JSON.parse(text) : {} + } catch (cause) { + throw new Error( + `Expected a JSON response but received ${response.headers.get("content-type") || "an unknown content type"} ` + + `(HTTP ${response.status}). This is usually a proxy or gateway error page, not the API.`, + { cause }, + ) + } + break + } + // altimate_change end case "stream": return opts.responseStyle === "data" ? response.body diff --git a/packages/sdk/js/src/v2/gen/client/client.gen.ts b/packages/sdk/js/src/v2/gen/client/client.gen.ts index 627e98ec42..67915f39ac 100644 --- a/packages/sdk/js/src/v2/gen/client/client.gen.ts +++ b/packages/sdk/js/src/v2/gen/client/client.gen.ts @@ -169,7 +169,19 @@ export const createClient = (config: Config = {}): Client => { // Some servers return 200 with no Content-Length and empty body. // response.json() would throw; read as text and parse if non-empty. const text = await response.text() - data = text ? JSON.parse(text) : {} + // altimate_change start — upstream_fix: guard JSON parse against non-JSON (HTML) response bodies + // A 200 whose body is an HTML error page from a proxy/gateway/CDN otherwise crashes with a + // raw "JSON Parse error: Unrecognized token '<'". Surface an actionable error instead. + try { + data = text ? JSON.parse(text) : {} + } catch (cause) { + throw new Error( + `Expected a JSON response but received ${response.headers.get("content-type") || "an unknown content type"} ` + + `(HTTP ${response.status}). This is usually a proxy or gateway error page, not the API.`, + { cause }, + ) + } + // altimate_change end break } case "stream":