Skip to content

Commit

Permalink
fix(websockets): websocket refersh token action is failing on refresh
Browse files Browse the repository at this point in the history
We silently ignore the error and report to our system instead of hard
crashin.

fixes LATITUDE-LLM-APP-83
  • Loading branch information
geclos committed Nov 20, 2024
1 parent 33a4704 commit e587080
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions apps/web/src/components/Providers/WebsocketsProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
}
}
})
Expand Down

0 comments on commit e587080

Please sign in to comment.