Repository navigation
feat: expose the parsed API error on StreamError - #388
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the API returns an error,
ApiClientparses the JSON body (APIError) but only copiescodeandmessageinto the thrownStreamError. Everything else the server sends is lost, most notablyexception_fields, which names the field that caused a validation or conflict error (for examplelast_message_idon a stale channel rewind, or the fork target onfork_target_exists).This adds an optional
apiErrorproperty toStreamError, holding the parsed error body as returned by the API (exception_fields,details,more_info,status_code,unrecoverable, ...).StreamErrorgains a fifth, optional constructor argumentapiError?: APIError. Existing call sites andinstanceofchecks are unaffected.ApiClient.sendRequestpasses the parsed body when the error response is JSON.apiErrorstaysundefinedfor network failures, timeouts, and non-JSON error bodies.Why
The Chat QA suite (GetStream/chat#16042) asserts
exception_fieldson 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, mockingfetchlikenetwork-error.test.ts:apiErrorequals the body, includingexception_fieldsapiErrorisundefinedand the message staysStream error: 502 - Bad Gatewayyarn tsc --noEmit, ESLint, Prettier andyarn buildpass; the emittedStreamErrordeclaration includesapiError.