From e587080cf736127f433c73715cb1743f5b1b2b76 Mon Sep 17 00:00:00 2001 From: Gerard Clos Date: Wed, 20 Nov 2024 14:18:36 +0100 Subject: [PATCH] fix(websockets): websocket refersh token action is failing on refresh We silently ignore the error and report to our system instead of hard crashin. fixes LATITUDE-LLM-APP-83 --- .../Providers/WebsocketsProvider/index.tsx | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/web/src/components/Providers/WebsocketsProvider/index.tsx b/apps/web/src/components/Providers/WebsocketsProvider/index.tsx index 35f46fc7b..2082605a6 100644 --- a/apps/web/src/components/Providers/WebsocketsProvider/index.tsx +++ b/apps/web/src/components/Providers/WebsocketsProvider/index.tsx @@ -14,6 +14,7 @@ import { Workspace, } from '@latitude-data/core/browser' import { useSession, useToast } from '@latitude-data/web-ui' +import * as Sentry from '@sentry/nextjs' import { refreshWebesocketTokenAction } from '$/actions/user/refreshWebsocketTokenAction' import { IoProvider, useSocket } from 'socket.io-react-hook' @@ -55,16 +56,20 @@ export function useSocketConnection({ connection.socket.on('connect_error', async (error) => { if (error.message.startsWith('AUTH_ERROR')) { - const [data] = await refreshWebesocketTokenAction() + try { + const [data] = await refreshWebesocketTokenAction() - if (data && data.success) { - connection.socket.connect() - } else { - toast({ - title: 'We have a problem reconnecting to the server', - description: 'Try logout and login again', - variant: 'destructive', - }) + if (data && data.success) { + connection.socket.connect() + } else { + toast({ + title: 'We have a problem reconnecting to the server', + description: 'Try logout and login again', + variant: 'destructive', + }) + } + } catch (e) { + Sentry.captureException(e as Error) } } })