From 06d09b89897ddc3f34a7b4fedacce14255904663 Mon Sep 17 00:00:00 2001 From: Ionut Achim Date: Wed, 13 Sep 2023 13:54:44 +0300 Subject: [PATCH] perf(synchronizer): prevent suppressions api request if access token is empty --- packages/synchronizer/src/utils/synchronizer.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/synchronizer/src/utils/synchronizer.ts b/packages/synchronizer/src/utils/synchronizer.ts index 7a12771f3..5704bb55e 100644 --- a/packages/synchronizer/src/utils/synchronizer.ts +++ b/packages/synchronizer/src/utils/synchronizer.ts @@ -109,10 +109,16 @@ export class Synchronizer extends EventEmitter { }; } - async getSuppressions(rootPath: string, accessToken?: string): Promise; - async getSuppressions(repoData: RepoRemoteData, accessToken?: string): Promise; - async getSuppressions(projectData: ProjectInputData, accessToken?: string): Promise; - async getSuppressions(rootPathOrRepoDataOrProjectData: string | RepoRemoteData | ProjectInputData, accessToken = '') { + async getSuppressions(rootPath: string, accessToken: string): Promise; + async getSuppressions(repoData: RepoRemoteData, accessToken: string): Promise; + async getSuppressions(projectData: ProjectInputData, accessToken: string): Promise; + async getSuppressions( + rootPathOrRepoDataOrProjectData: string | RepoRemoteData | ProjectInputData, + accessToken: string + ) { + if (!accessToken || accessToken?.length === 0) { + throw new Error('Cannot fetch without access token.'); + } const inputData = await this.getRepoOrProjectData(rootPathOrRepoDataOrProjectData); const suppressions = await this.fetchSuppressionsForRepo(inputData as any, accessToken); return suppressions;