fix: handle network errors during login to prevent TypeError crash#1261
Open
mufeezhanif wants to merge 1 commit intoRocketChat:developfrom
Open
fix: handle network errors during login to prevent TypeError crash#1261mufeezhanif wants to merge 1 commit intoRocketChat:developfrom
mufeezhanif wants to merge 1 commit intoRocketChat:developfrom
Conversation
The login method in EmbeddedChatApi.ts returned undefined when a non-401 error occurred (e.g. network failure). This caused a TypeError in useRCAuth.js when accessing res.error on the undefined response, crashing the login flow silently. Changes: - EmbeddedChatApi.ts: return an error object for all caught errors instead of implicitly returning undefined - useRCAuth.js: add a null guard on the login response as a safety net, showing a toast message if the response is missing Fixes RocketChat#1210
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
Fixes #1210 — login crashes with
TypeError: Cannot read properties of undefined (reading 'error')when a network error occurs during authentication.Root Cause
The
loginmethod inEmbeddedChatApi.tscatches errors but only returns a structured response for 401 errors. For all other errors (network failures, DNS errors, etc.), itconsole.error()s and implicitly returnsundefined. The calling code inuseRCAuth.jsthen tries to accessres.error, which throws aTypeError.Changes
packages/api/src/EmbeddedChatApi.ts{ error: error.message }(or{ error: 'unknown-error' }) for all non-401 errors instead of implicitly returningundefinedpackages/react/src/hooks/useRCAuth.jsTesting
handleLoginstill handles truly unexpected errors