From d0cc39c6a76b6524d2cb994dd1b15e02be4c019f Mon Sep 17 00:00:00 2001 From: Marcos Carlomagno Date: Tue, 23 Jul 2024 11:26:23 -0300 Subject: [PATCH] Handle API key invalid response (#478) * handle api key invalid response * lint --- packages/base/src/api/client.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/base/src/api/client.ts b/packages/base/src/api/client.ts index 8d7b2b10..b1168181 100644 --- a/packages/base/src/api/client.ts +++ b/packages/base/src/api/client.ts @@ -133,6 +133,10 @@ export abstract class BaseApiClient { await sleep(retryDelay); return await apiFunction(axiosInstance); } catch (error: any) { + if (isForbiddenError(error)) { + throw new Error('API Key is either expired or invalid'); + } + // this means ID token has expired so we'll recreate session and try again if (isAuthenticationError(error)) { this.api = undefined; @@ -188,3 +192,6 @@ export const exponentialDelay = ( const randomSum = delay * 0.2 * Math.random(); // 0-20% of the delay return delay + randomSum; }; + +const isForbiddenError = (axiosError: AxiosError): boolean => + axiosError.response?.status === 403 && axiosError.response?.statusText === 'Forbidden';