diff --git a/lib/process-services-cloud/src/lib/services/web-socket.service.ts b/lib/process-services-cloud/src/lib/services/web-socket.service.ts index 79af5f059b..e85afc3324 100644 --- a/lib/process-services-cloud/src/lib/services/web-socket.service.ts +++ b/lib/process-services-cloud/src/lib/services/web-socket.service.ts @@ -141,9 +141,25 @@ export class WebSocketService { max: Number.POSITIVE_INFINITY, jitter: true }, - attempts: { - max: 5, - retryIf: (error) => !!error + attempts: (count: number, _operation: Operation, error: any) => { + if (!error) { + return false; + } + + const isUnauthorizedError = + (Array.isArray(error) && + error.some( + (err: any) => + err?.extensions?.code === 'UNAUTHORIZED' || + err?.message?.includes('4401') || + err?.message?.toLowerCase().includes('unauthorized') + )) || + (typeof error === 'string' && (error.includes('4401') || error.toLowerCase().includes('unauthorized'))) || + (error?.message && (error.message.includes('4401') || error.message.toLowerCase().includes('unauthorized'))); + + const shouldRetry = isUnauthorizedError ? this.authService.isLoggedIn() : count < 5; + + return shouldRetry; } });