diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts index f1ccc44a99..1233b1e2f9 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts @@ -216,6 +216,7 @@ export class MicrosoftGraphClient { async requestRaw( url: string, headers?: Record, + retryCount = 2, ): Promise { // Make sure that we always have a valid access token (might be cached) const urlObj = new URL(url); @@ -227,12 +228,19 @@ export class MicrosoftGraphClient { throw new Error('Failed to obtain token from Azure Identity'); } - return await fetch(url, { - headers: { - ...headers, - Authorization: `Bearer ${token.token}`, - }, - }); + try { + return await fetch(url, { + headers: { + ...headers, + Authorization: `Bearer ${token.token}`, + }, + }); + } catch (e: any) { + if (e?.code === 'ETIMEDOUT' && retryCount > 0) { + return this.requestRaw(url, headers, retryCount - 1); + } + throw e; + } } /**