From c77e60e1688800a4f6b018cc6e9c1ce89033f108 Mon Sep 17 00:00:00 2001 From: Abir Majumdar Date: Thu, 9 May 2024 15:30:39 -0400 Subject: [PATCH 1/2] Add error handling for missing GitHub token and explicitly stating VUE_APP_MOCKED_DATA=true in the UI --- src/api/GitHubApi.ts | 6 +++++- src/components/MainComponent.vue | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/api/GitHubApi.ts b/src/api/GitHubApi.ts index 9d3c1aa1..d8ddb682 100644 --- a/src/api/GitHubApi.ts +++ b/src/api/GitHubApi.ts @@ -17,7 +17,7 @@ export const getMetricsApi = async (): Promise => { let metricsData; if (process.env.VUE_APP_MOCKED_DATA === "true") { - + console.log("Using mock data. Check VUE_APP_MOCKED_DATA variable."); if (process.env.VUE_APP_SCOPE === "organization") { response = organizationMockedResponse; } else if (process.env.VUE_APP_SCOPE === "enterprise") { @@ -28,6 +28,10 @@ export const getMetricsApi = async (): Promise => { metricsData = response.map((item: any) => new Metrics(item)); } else { + // if VUE_APP_GITHUB_TOKEN is not set, throw an error + if (!process.env.VUE_APP_GITHUB_TOKEN) { + throw new Error("VUE_APP_GITHUB_TOKEN environment variable is not set."); + } if (process.env.VUE_APP_SCOPE === "organization") { response = await axios.get( `https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/usage`, diff --git a/src/components/MainComponent.vue b/src/components/MainComponent.vue index ba1f935b..68661c48 100644 --- a/src/components/MainComponent.vue +++ b/src/components/MainComponent.vue @@ -6,7 +6,7 @@ Copilot Metrics Viewer | {{ capitalizedItemName }} : {{ gitHubOrgName }} -

+

{{ mockedDataMessage }}