Repository navigation
fix(api,react): propagate _doConnect errors and reset auth state on failure - #1485
Open
ashwanisingh011 wants to merge 1 commit into
Open
ashwanisingh011 wants to merge 1 commit into
ashwanisingh011 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
fix(api,react): propagate
_doConnecterrors instead of resolving silentlySummary
Previously,
EmbeddedChatApi._doConnect()caught connection/login errors, calledthis.close()withoutawait, and swallowed the error instead of rethrowing it. As a result,RCInstance.connect()resolved instead of rejecting—causingEmbeddedChatto falsely log"Connected to RocketChat ...", setisUserAuthenticated(true), and trigger authenticated REST fetches that failed with401 (Unauthorized)and aTypeErrorinuseFetchChatData.Fixes: #1484
Changes
packages/api/src/EmbeddedChatApi.ts:await this.close()before connecting and inside thecatch (err)block.errfrom_doConnect()soRCInstance.connect()rejects on failure.packages/react/src/views/EmbeddedChat.js:RCInstance.connect(...).catch(...), log the error and resetsetIsUserAuthenticated(false)when still mounted for the sameuser, preventing stale/broken authenticated UI state on connection failure.Acceptance Criteria fulfillment
_doConnect()awaitsthis.close()and rethrows connection/auth errors instead of resolving silently.EmbeddedChathandles rejectedRCInstance.connect()promises without transitioning into a broken authenticated state.Video/Screenshots
develop)fix/propagate-doconnect-errors)_doConnectswallows the thrown error:EmbeddedChat.js:206falsely logsConnected to RocketChat http://localhost:3000, showsMessage #undefined, and triggers401 (Unauthorized)errors (19 console errors)._doConnectawaitsclose()and rethrows:EmbeddedChat.js:218logsError: Simulated WebSocket failurecleanly, and UI stays in the unauthenticatedJOINstate (1 console error, zero401cascade).PR Test Details
http://localhost:3000, CORS enabled) and EmbeddedChat Storybook (http://localhost:6006,EmbeddedChat/Simple).await this.sdk.connection.connect();inEmbeddedChatApi.tsand simulated a WebSocket failure:develop): Console printedConnected to RocketChat http://localhost:3000followed by401 (Unauthorized)errors across room endpoints (rooms.info,permissions.listAll,channels.messages, etc.) while UI renderedMessage #undefined.fix/propagate-doconnect-errors): Rebuilt@embeddedchat/api(yarn build), restarted Storybook, repeated the same simulation—Console logged onlyError: Simulated WebSocket failureatEmbeddedChat.js:218, with no false"Connected"log, no401cascade, and UI remaining in theJOINstate.Note: The PR will be ready for live testing at https://rocketchat.github.io/EmbeddedChat/pulls/pr-<pr_number> after approval. Contributors are requested to replace
<pr_number>with the actual PR number.