Skip to content

Commit

Permalink
Handle API key invalid response (#478)
Browse files Browse the repository at this point in the history
* handle api key invalid response

* lint
  • Loading branch information
MCarlomagno authored Jul 23, 2024
1 parent b04b355 commit d0cc39c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/base/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';

0 comments on commit d0cc39c

Please sign in to comment.