Skip to content

feat: expose the parsed API error on StreamError - #388

Merged
oliverlaz merged 1 commit into
mainfrom
feat/stream-error-api-error
Nov 9, 2026
Merged

oliverlaz merged 1 commit into
mainfrom
feat/stream-error-api-error

Conversation

@oliverlaz

Copy link
Copy Markdown
Member

Summary

When the API returns an error, ApiClient parses the JSON body (APIError) but only copies code and message into the thrown StreamError. Everything else the server sends is lost, most notably exception_fields, which names the field that caused a validation or conflict error (for example last_message_id on a stale channel rewind, or the fork target on fork_target_exists).

This adds an optional apiError property to StreamError, holding the parsed error body as returned by the API (exception_fields, details, more_info, status_code, unrecoverable, ...).

  • StreamError gains a fifth, optional constructor argument apiError?: APIError. Existing call sites and instanceof checks are unaffected.
  • ApiClient.sendRequest passes the parsed body when the error response is JSON. apiError stays undefined for network failures, timeouts, and non-JSON error bodies.

Why

The Chat QA suite (GetStream/chat#16042) asserts exception_fields on rewind and fork conflict errors. It moved to node-sdk 0.9.0 and can no longer reach them, so those assertions currently only check the status, code and message.

Tests

New __tests__/integration/api-error.test.ts, mocking fetch like network-error.test.ts:

  • a 409 with a JSON error body: apiError equals the body, including exception_fields
  • a 502 with an HTML body: apiError is undefined and the message stays Stream error: 502 - Bad Gateway

yarn tsc --noEmit, ESLint, Prettier and yarn build pass; the emitted StreamError declaration includes apiError.

@oliverlaz
oliverlaz requested a review from szuperaz as a code owner November 9, 2026 10:43
@oliverlaz
oliverlaz merged commit 13770c8 into main Nov 9, 2026
10 checks passed
@oliverlaz
oliverlaz deleted the feat/stream-error-api-error branch November 9, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant