Skip to content

fix: Prevent crash when login API returns undefined - #1393

Open
aryanpatil-07 wants to merge 2 commits into
RocketChat:developfrom
aryanpatil-07:fix/login-undefined-response-crash
Open

aryanpatil-07 wants to merge 2 commits into
RocketChat:developfrom
aryanpatil-07:fix/login-undefined-response-crash

Conversation

@aryanpatil-07

@aryanpatil-07 aryanpatil-07 commented Oct 17, 2026 •

Copy link
Copy Markdown

fix: Prevent TypeError crash when login API returns undefined

Acceptance Criteria fulfillment

  • Prevent unhandled TypeError: Cannot read properties of undefined (reading 'error') when RCInstance.login returns undefined.
  • Add guard check to display a user-friendly error toast message when the server is unreachable or offline.
  • Verify local build and linting checks pass with zero regression.

Note: This bug was discovered and fixed directly during local development while testing offline/unreachable server scenarios.

Video/Screenshots

image

PR Test Details

  1. Run the development server without a local Rocket.Chat backend running on port 3000.
  2. Attempt to submit credentials in the login dialog.
  3. Observe that instead of an uncaught TypeError in the browser console, a clean error toast notification is displayed informing the user that the server is unreachable.

Note: The PR will be ready for live testing at https://rocketchat.github.io/EmbeddedChat/pulls/pr-1393 after approval. Contributors are requested to replace <pr_number> with the actual PR number.

@CLAassistant

CLAassistant commented Oct 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@aryanpatil-07
aryanpatil-07 marked this pull request as ready for review October 17, 2026 18:25
@Aryan-Verma-999

Copy link
Copy Markdown
Collaborator

Could you please add a short demo video showing the offline/unreachable-server login flow and confirming there is no console TypeError?

@aryanpatil-07

Copy link
Copy Markdown
Author

Hi @Aryan-Verma-999,

Thanks for reviewing! Here is a short demo video showing the unreachable-server login attempt with DevTools open side-by-side:

Screen.Recording.2026-10-23.160037.mp4

As shown in the recording:

  • The UI gracefully captures the network failure and displays the error toast message.
  • The browser console logs the expected ERR_CONNECTION_REFUSED / Failed to fetch without throwing the previous unhandled TypeError: Cannot read properties of undefined (reading 'error').

Please let me know if any other adjustments are needed!

@Aryan-Verma-999

Copy link
Copy Markdown
Collaborator

Thanks for the demo. The guard removes the secondary TypeError, but the underlying issue is that EmbeddedChatApi.login() catches non-401/network errors and implicitly returns undefined.
Could you instead rethrow non-401 errors from login()? useRCAuth already catches thrown errors and displays the connection-error toast, so this keeps the API contract clear: it either returns a login result or throws.

@aryanpatil-07

aryanpatil-07 commented Oct 23, 2026 •

Copy link
Copy Markdown
Author

Hi @Aryan-Verma-999,

That makes total sense, keeping the API contract strict by either returning the login result or throwing is much cleaner.

I have updated EmbeddedChatApi.login() to rethrow non-401 errors so they propagate directly to useRCAuth's existing error handling, and reverted the UI-level guard check. Tested locally to verify that network errors cleanly trigger the connection toast without any unhandled TypeErrors.

Thanks for the feedback!

This branch has not been deployed

No deployments
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.

3 participants