Skip to content

Commit

Permalink
Merge pull request #29 from abirismyname/adding-more-error-handling
Browse files Browse the repository at this point in the history
Add error handling for missing GitHub token and explicitly stating VUE_APP_MOCKED_DATA=true in the UI
  • Loading branch information
martedesco authored May 30, 2024
2 parents 7d3740f + d085f23 commit c5ccd1d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/api/GitHubApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getMetricsApi = async (): Promise<Metrics[]> => {
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") {
Expand All @@ -28,6 +28,10 @@ export const getMetricsApi = async (): Promise<Metrics[]> => {

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`,
Expand Down
5 changes: 4 additions & 1 deletion src/components/MainComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</v-btn>

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

<template v-slot:extension>
Expand Down Expand Up @@ -74,6 +74,9 @@ export default defineComponent({
},
capitalizedItemName() {
return this.itemName.charAt(0).toUpperCase() + this.itemName.slice(1);
},
mockedDataMessage() {
return process.env.VUE_APP_MOCKED_DATA === 'true' ? 'Using mock data - see README if unintended' : '';
}
},
data () {
Expand Down

0 comments on commit c5ccd1d

Please sign in to comment.