Skip to content

Commit c2fdb98

Browse files
committed
fix: handle network errors during login to prevent TypeError crash
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 #1210
1 parent e1a4d84 commit c2fdb98

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

packages/api/src/EmbeddedChatApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export default class EmbeddedChatApi {
143143
return { error: authErrorRes?.error };
144144
}
145145
console.error(error);
146+
return { error: error instanceof Error ? error.message : 'unknown-error' };
146147
}
147148
}
148149

packages/react/src/hooks/useRCAuth.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ export const useRCAuth = () => {
2525
const handleLogin = async (userOrEmail, password, code) => {
2626
try {
2727
const res = await RCInstance.login(userOrEmail, password, code);
28+
if (!res) {
29+
dispatchToastMessage({
30+
type: 'error',
31+
message:
32+
'Unable to connect to server. Please check your connection and try again.',
33+
});
34+
return;
35+
}
2836
if (res.error === 'Unauthorized' || res.error === 403) {
2937
dispatchToastMessage({
3038
type: 'error',

0 commit comments

Comments
 (0)