Skip to content

Commit

Permalink
fix: error handling on chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuzhy-Deriv committed Nov 28, 2024
1 parent 69df0f8 commit a30fbc3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/utils/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ export const Chat = {
clear: async () => {
const { isFreshChat, isIntercom } = await Chat.getFlags();
if (isFreshChat) {
window.fcWidget?.user.clear().then(() => window.fcWidget.destroy());
window.fcWidget?.user
.clear()
.then(() => window.fcWidget.destroy())
.catch((error: Error) => {
// eslint-disable-next-line no-console
console.error('Failed to clear FreshChat:', error);
});
} else if (isIntercom && window.Intercom) {
window.Intercom('shutdown');
}
Expand All @@ -18,8 +24,12 @@ export const Chat = {
},

getFlags: async () => {
const [isFreshChat, isIntercom] = await Promise.all([Chat.isFreshChat(), Chat.isIntercom()]);
return { isFreshChat, isIntercom };
try {
const [isFreshChat, isIntercom] = await Promise.all([Chat.isFreshChat(), Chat.isIntercom()]);
return { isFreshChat, isIntercom };
} catch (error) {
return { isFreshChat: false, isIntercom: false };
}
},

isFreshChat: async () => getFeatureFlag('enable_freshworks_live_chat_p2p'),
Expand Down

0 comments on commit a30fbc3

Please sign in to comment.