Skip to content

Commit c5ccd1d

Browse files
authored
Merge pull request #29 from abirismyname/adding-more-error-handling
Add error handling for missing GitHub token and explicitly stating VUE_APP_MOCKED_DATA=true in the UI
2 parents 7d3740f + d085f23 commit c5ccd1d

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>
@@ -74,6 +74,9 @@ export default defineComponent({
7474
},
7575
capitalizedItemName() {
7676
return this.itemName.charAt(0).toUpperCase() + this.itemName.slice(1);
77+
},
78+
mockedDataMessage() {
79+
return process.env.VUE_APP_MOCKED_DATA === 'true' ? 'Using mock data - see README if unintended' : '';
7780
}
7881
},
7982
data () {

0 commit comments

Comments
 (0)