Skip to content

Commit 97f480d

Browse files
committed
Delete HelloWorld.vue and add error handling to MetricsViewer.vue
1 parent dcdaf17 commit 97f480d

File tree

2 files changed

+48
-74
lines changed

2 files changed

+48
-74
lines changed

src/components/HelloWorld.vue

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/components/MetricsViewer.vue

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
<div>
33
<h1>GitHub Copilot Business Metrics Viewer</h1>
44

5-
<h2>Acceptance rate (%)</h2>
6-
<Bar :data="acceptanceRateChartData" :options="chartOptions" />
5+
<!-- API Error Message -->
6+
<div v-if="apiError" class="error-message" v-html="apiError"></div>
7+
<div v-if="!apiError">
8+
<h2>Acceptance rate (%)</h2>
9+
<Bar :data="acceptanceRateChartData" :options="chartOptions" />
710

8-
<h2>Total Suggestions Count | Total Acceptances Count</h2>
9-
<Line :data="totalSuggestionsAndAcceptanceChartData" :options="chartOptions" />
11+
<h2>Total Suggestions Count | Total Acceptances Count</h2>
12+
<Line :data="totalSuggestionsAndAcceptanceChartData" :options="chartOptions" />
1013

11-
<h2>Total Lines Suggested | Total Lines Accepted</h2>
12-
<Line :data="chartData" :options="chartOptions" />
13-
14-
<h2>Total Active Users</h2>
15-
<Bar :data="totalActiveUsersChartData" :options="totalActiveUsersChartOptions" />
14+
<h2>Total Lines Suggested | Total Lines Accepted</h2>
15+
<Line :data="chartData" :options="chartOptions" />
1616

17+
<h2>Total Active Users</h2>
18+
<Bar :data="totalActiveUsersChartData" :options="totalActiveUsersChartOptions" />
19+
</div>
1720
</div>
1821
</template>
1922

@@ -68,13 +71,17 @@ export default defineComponent({
6871
//Total Active Users
6972
const totalActiveUsersChartData = ref<{ labels: string[]; datasets: any[] }>({ labels: [], datasets: [] });
7073
74+
// API Error Message
75+
const apiError = ref<string | null>(null);
76+
77+
7178
const chartOptions = {
7279
responsive: true,
7380
maintainAspectRatio: true,
7481
layout: {
7582
padding: {
76-
left: 40,
77-
right: 40,
83+
left: 150,
84+
right: 150,
7885
top: 20,
7986
bottom: 40
8087
}
@@ -173,9 +180,37 @@ export default defineComponent({
173180
}
174181
]
175182
};
183+
}).catch(error => {
184+
console.log(error);
185+
// Check the status code of the error response
186+
if (error.response && error.response.status) {
187+
switch (error.response.status) {
188+
case 401:
189+
apiError.value = '401 Unauthorized access - check if your token in the .env file is correct.';
190+
break;
191+
case 404:
192+
apiError.value = `404 Not Found - is the organization '${process.env.VUE_APP_GITHUB_ORG}' correct?`;
193+
break;
194+
default:
195+
apiError.value = error.message;
196+
break;
197+
}
198+
} else {
199+
// Update apiError with the error message
200+
apiError.value = error.message;
201+
}
202+
// Add a new line to the apiError message
203+
apiError.value += ' <br> If .env file is modified, restart the changes to take effect.';
204+
176205
});
177206
178-
return { totalSuggestionsAndAcceptanceChartData, chartData, chartOptions, totalActiveUsersChartData, totalActiveUsersChartOptions, acceptanceRateChartData };
207+
return { totalSuggestionsAndAcceptanceChartData, chartData, chartOptions, totalActiveUsersChartData, totalActiveUsersChartOptions, acceptanceRateChartData, apiError };
179208
}
180209
});
181-
</script>
210+
</script>
211+
212+
<style scoped>
213+
.error-message {
214+
color: red;
215+
}
216+
</style>

0 commit comments

Comments
 (0)