From 10346dbf1fb98ddc8e4c047d3ddb78dd4afec95c Mon Sep 17 00:00:00 2001 From: alep85 Date: Mon, 14 Apr 2025 14:56:26 +0200 Subject: [PATCH] AAE-30358 Update Retry connection logic to allow retry when the graphql return unauthorized error --- .../src/lib/services/web-socket.service.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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; } });