From 769bb7806f441c25ed2000ca0bce0be911e97605 Mon Sep 17 00:00:00 2001 From: Edda Solem Date: Wed, 12 Jun 2024 15:44:45 +0200 Subject: [PATCH] Prevent frontend from crashing on empty signalR msg --- frontend/src/components/Contexts/SignalRContext.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/Contexts/SignalRContext.tsx b/frontend/src/components/Contexts/SignalRContext.tsx index 83bbd2f7c..dd11aca6c 100644 --- a/frontend/src/components/Contexts/SignalRContext.tsx +++ b/frontend/src/components/Contexts/SignalRContext.tsx @@ -81,7 +81,14 @@ export const SignalRProvider: FC = ({ children }) => { }, [accessToken]) const registerEvent = (eventName: string, onMessageReceived: (username: string, message: string) => void) => { - if (connection) connection.on(eventName, (username, message) => onMessageReceived(username, message)) + if (connection) + connection.on(eventName, (username, message) => { + if (message === 'null') { + console.warn(`Received signalR message for event ${eventName} is 'null'`) + return + } + onMessageReceived(username, message) + }) } return (