Skip to content

SDK client crashes with a raw JSON parse error on non-JSON (HTML) API responses #1119

Description

@ralphstodomingo

Describe the bug

When a proxy / gateway / CDN returns an HTTP 200 with an HTML body (an error or interstitial page) instead of JSON, the generated SDK client crashes with a raw JSON Parse error: Unrecognized token '<'.

parseAs falls back to "json" whenever Content-Type is missing or unrecognized, so a non-JSON body reaches JSON.parse unguarded on the success path (the error-response path is already guarded). Surfaces to users as chat sendMessageError with an unactionable parse error (~11 machines / 7d in telemetry).

Expected behavior

An actionable error naming the received content-type and HTTP status (e.g. "Expected a JSON response but received text/html (HTTP 200) — usually a proxy or gateway error page"), instead of a raw parse crash.

To Reproduce

  1. Point the CLI's backend at an endpoint returning 200 + an HTML body (with a JSON or missing content-type).
  2. Send a chat message.
  3. Observe SyntaxError: JSON Parse error: Unrecognized token '<' instead of a useful error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions