From bf5b7553d5ad56db9a7130ffbd8a1e10a8f9228d Mon Sep 17 00:00:00 2001 From: Mamadou DICKO <63923024+mamadoudicko@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:26:25 +0200 Subject: [PATCH] fix: wrap parsing with try catch (#1321) --- .../NotificationDisplayer.tsx | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend/app/chat/[chatId]/components/ChatDialogueArea/components/ChatDialogue/components/ChatNotification/components/NotificationDisplayer/NotificationDisplayer.tsx b/frontend/app/chat/[chatId]/components/ChatDialogueArea/components/ChatDialogue/components/ChatNotification/components/NotificationDisplayer/NotificationDisplayer.tsx index ae662ec44..3d901e2b4 100644 --- a/frontend/app/chat/[chatId]/components/ChatDialogueArea/components/ChatDialogue/components/ChatNotification/components/NotificationDisplayer/NotificationDisplayer.tsx +++ b/frontend/app/chat/[chatId]/components/ChatDialogueArea/components/ChatDialogue/components/ChatNotification/components/NotificationDisplayer/NotificationDisplayer.tsx @@ -20,9 +20,19 @@ export const NotificationDisplayer = ({ return ; } - const { message, status, name } = JSON.parse( - nonParsedMessage.replace(/'/g, '"') - ) as NotificationMessage; + let message, status, name; + + try { + const parsedMessage = JSON.parse( + nonParsedMessage.replace(/'/g, '"') + ) as NotificationMessage; + + message = parsedMessage.message; + status = parsedMessage.status; + name = parsedMessage.name; + } catch (error) { + return ; + } return (
{isHovered && ( -
{message}