Skip to content

Bug: Uncaught TypeError in useRCAuth on Network Error during login #1210

@deepak0x

Description

@deepak0x

When a user attempts to log in but encounters a network error (e.g., net::ERR_NETWORK_CHANGED or a DNS failure), the fetch call in EmbeddedChatApi.login throws an error.

The catch block in packages/api/src/EmbeddedChatApi.ts currently logs the error but implicitly returns undefined:

// packages/api/src/EmbeddedChatApi.ts
      if (error instanceof ApiError && error.response?.status === 401) {
        const authErrorRes = await error.response.json();
        return { error: authErrorRes?.error };
      }
      console.error(error); // returns undefined implicitly

Subsequently, the react hook useRCAuth.js attempts to read res.error, leading to an uncaught TypeError, completely crashing the login flow and preventing any toast error message from being displayed to the user:

// packages/react/src/hooks/useRCAuth.js
      const res = await RCInstance.login(userOrEmail, password, code);
      if (res.error === 'Unauthorized' || res.error === 403) { // TypeError: Cannot read properties of undefined (reading 'error')

Steps To Reproduce

  1. Open the EmbeddedChat application
  2. Go to the offline state or throttle your network connection to drop it mid-request.
  3. Attempt to submit the login form.
  4. Observe the unhandled promise rejection and UI crash instead of a graceful toast message.

Expected Behavior

The login flow should robustly handle network errors returned by RCInstance.login(), exiting gracefully and optionally displaying a user-friendly error toast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions