Skip to content

Commit c77e60e

Browse files
committed
Add error handling for missing GitHub token and explicitly stating VUE_APP_MOCKED_DATA=true in the UI
1 parent 27e631b commit c77e60e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/api/GitHubApi.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const getMetricsApi = async (): Promise<Metrics[]> => {
1717
let metricsData;
1818

1919
if (process.env.VUE_APP_MOCKED_DATA === "true") {
20-
20+
console.log("Using mock data. Check VUE_APP_MOCKED_DATA variable.");
2121
if (process.env.VUE_APP_SCOPE === "organization") {
2222
response = organizationMockedResponse;
2323
} else if (process.env.VUE_APP_SCOPE === "enterprise") {
@@ -28,6 +28,10 @@ export const getMetricsApi = async (): Promise<Metrics[]> => {
2828

2929
metricsData = response.map((item: any) => new Metrics(item));
3030
} else {
31+
// if VUE_APP_GITHUB_TOKEN is not set, throw an error
32+
if (!process.env.VUE_APP_GITHUB_TOKEN) {
33+
throw new Error("VUE_APP_GITHUB_TOKEN environment variable is not set.");
34+
}
3135
if (process.env.VUE_APP_SCOPE === "organization") {
3236
response = await axios.get(
3337
`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/usage`,

src/components/MainComponent.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</v-btn>
77

88
<v-toolbar-title>Copilot Metrics Viewer | {{ capitalizedItemName }} : {{ gitHubOrgName }}</v-toolbar-title>
9-
<h2> </h2>
9+
<h2 class="error-message"> {{ mockedDataMessage }} </h2>
1010
<v-spacer></v-spacer>
1111

1212
<template v-slot:extension>
@@ -73,6 +73,9 @@ export default defineComponent({
7373
},
7474
capitalizedItemName() {
7575
return this.itemName.charAt(0).toUpperCase() + this.itemName.slice(1);
76+
},
77+
mockedDataMessage() {
78+
return process.env.VUE_APP_MOCKED_DATA === 'true' ? 'Using mock data. Check VUE_APP_MOCKED_DATA variable.' : '';
7679
}
7780
},
7881
data () {

0 commit comments

Comments
 (0)