Skip to content

Commit e160c4b

Browse files
author
dmitriyakkerman
committed
widget update
1 parent 219da2e commit e160c4b

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-youtube-widget",
3-
"version": "0.1.0",
3+
"version": "0.5.0",
44
"scripts": {
55
"serve": "vue-cli-service serve",
66
"build": "vue-cli-service build --target lib --name YoutubeWidget ./src/components/YouTubeWidget.vue",

src/components/YouTubeWidget.vue

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,66 @@
7272
async getChannelTitleAndAvatar() {
7373
this.isSending = true;
7474
75-
const response = await getChannelTitleAndAvatar(this.channelId, this.apiKey);
76-
77-
this.channelAvatar = response["items"][0].snippet.thumbnails.default.url;
78-
this.channelTitle = response["items"][0].snippet.localized.title;
79-
80-
this.isSending = false;
75+
try {
76+
const response = await getChannelTitleAndAvatar(this.channelId, this.apiKey);
77+
78+
this.channelAvatar = response["items"][0].snippet.thumbnails.default.url;
79+
this.channelTitle = response["items"][0].snippet.localized.title;
80+
}
81+
catch(error) {
82+
console.log(error);
83+
}
84+
finally {
85+
this.isSending = false;
86+
}
8187
},
8288
async getSubscribersCount() {
8389
this.isSending = true;
8490
85-
const response = await getSubscribersCount(this.channelId, this.apiKey);
86-
87-
this.subscribersCount = response["items"][0].statistics.subscriberCount;
88-
this.totalVideosCount = response["items"][0].statistics.videoCount;
89-
90-
this.isSending = false;
91+
try {
92+
const response = await getSubscribersCount(this.channelId, this.apiKey);
93+
94+
this.subscribersCount = response["items"][0].statistics.subscriberCount;
95+
this.totalVideosCount = response["items"][0].statistics.videoCount;
96+
}
97+
catch(error) {
98+
console.log(error);
99+
}
100+
finally {
101+
this.isSending = false;
102+
}
91103
},
92104
async getVideos() {
93105
this.isSending = true;
94106
95-
const response = await getVideos(this.channelId, this.apiKey, this.resultsPerRequest);
96-
97-
this.videos = response.items;
98-
this.nextPageToken = response.nextPageToken;
99-
100-
this.isSending = false;
107+
try {
108+
const response = await getVideos(this.channelId, this.apiKey, this.resultsPerRequest);
109+
110+
this.videos = response.items;
111+
this.nextPageToken = response.nextPageToken;
112+
}
113+
catch(error) {
114+
console.log(error);
115+
}
116+
finally {
117+
this.isSending = false;
118+
}
101119
},
102120
async loadMore() {
103121
this.isSending = true;
104122
105-
const response = await loadMoreVideos(this.channelId, this.apiKey, this.resultsPerRequest, this.nextPageToken);
106-
107-
this.videos = [...this.videos, ...response.items];
108-
this.nextPageToken = response.nextPageToken;
109-
110-
this.isSending = false;
123+
try {
124+
const response = await loadMoreVideos(this.channelId, this.apiKey, this.resultsPerRequest, this.nextPageToken);
125+
126+
this.videos = [...this.videos, ...response.items];
127+
this.nextPageToken = response.nextPageToken;
128+
}
129+
catch(error) {
130+
console.log(error);
131+
}
132+
finally {
133+
this.isSending = false;
134+
}
111135
},
112136
},
113137
mounted() {

0 commit comments

Comments
 (0)