17
17
</v-tabs >
18
18
</template >
19
19
</v-toolbar >
20
- <v-window v-model =" tab" >
20
+
21
+ <!-- API Error Message -->
22
+ <div v-if =" apiError" class =" error-message" v-html =" apiError" ></div >
23
+ <div v-if =" !apiError" >
24
+ <v-window v-if =" metricsReady" v-model =" tab" >
21
25
<v-window-item v-for =" item in items" :key =" item" :value =" item" >
22
26
<v-card flat >
23
- <MetricsViewer v-if =" item === 'organization'" />
27
+ <MetricsViewer v-if =" item === 'organization'" :metrics = " metrics " />
24
28
<LanguagesBreakdown v-if =" item === 'languages'" />
25
29
<CopilotChatViewer v-if =" item === 'copilot chat'" />
26
- <ApiResponse v-if =" item === 'api response'" />
30
+ <ApiResponse v-if =" item === 'api response'" :metrics = " metrics " />
27
31
</v-card >
28
32
</v-window-item >
29
33
</v-window >
34
+ </div >
35
+
30
36
</v-card >
31
37
</template >
32
38
@@ -35,7 +41,10 @@ import { defineComponent } from 'vue'
35
41
import MetricsViewer from ' ./MetricsViewer.vue'
36
42
import LanguagesBreakdown from ' ./LanguagesBreakdown.vue'
37
43
import CopilotChatViewer from ' ./CopilotChatViewer.vue'
38
- import ApiResponse from ' ./ApiResponse.vue'
44
+ import ApiResponse from ' ./ApiResponse.vue'
45
+ import { ref } from ' vue' ;
46
+ import { getGitHubCopilotMetricsApi } from ' ../api/GitHubApi' ;
47
+ import { Metrics } from ' ../model/MetricsData' ;
39
48
40
49
41
50
export default defineComponent ({
@@ -54,8 +63,53 @@ export default defineComponent({
54
63
data () {
55
64
return {
56
65
items: [' organization' , ' languages' , ' copilot chat' , ' api response' ],
57
- tab: null ,
66
+ tab: null
58
67
}
59
68
},
69
+ setup() {
70
+ const metricsReady = ref (false );
71
+ const metrics = ref <Metrics []>([]);
72
+
73
+ // API Error Message
74
+ const apiError = ref <string | undefined >(undefined );
75
+
76
+ getGitHubCopilotMetricsApi ().then (data => {
77
+ metrics .value = data ;
78
+
79
+ // Set metricsReady to true after the call completes.
80
+ metricsReady .value = true ;
81
+
82
+ }).catch (error => {
83
+ console .log (error );
84
+ // Check the status code of the error response
85
+ if (error .response && error .response .status ) {
86
+ switch (error .response .status ) {
87
+ case 401 :
88
+ apiError .value = ' 401 Unauthorized access - check if your token in the .env file is correct.' ;
89
+ break ;
90
+ case 404 :
91
+ apiError .value = ` 404 Not Found - is the organization '${process .env .VUE_APP_GITHUB_ORG }' correct? ` ;
92
+ break ;
93
+ default :
94
+ apiError .value = error .message ;
95
+ break ;
96
+ }
97
+ } else {
98
+ // Update apiError with the error message
99
+ apiError .value = error .message ;
100
+ }
101
+ // Add a new line to the apiError message
102
+ apiError .value += ' <br> If .env file is modified, restart the changes to take effect.' ;
103
+
104
+ });
105
+
106
+ return { metricsReady , metrics , apiError };
107
+ }
60
108
})
61
109
</script >
110
+
111
+ <style scoped>
112
+ .error-message {
113
+ color : red ;
114
+ }
115
+ </style >
0 commit comments