From 8548cf5a4da6326b4a6673f88c4e7cd9677f74c2 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 6 Apr 2024 12:05:16 +0200 Subject: [PATCH] feat: alert api error messages in feed and subscriptions --- src/components/FeedPage.vue | 29 +++++++--------------------- src/components/SubscriptionsPage.vue | 5 +++++ src/main.js | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/components/FeedPage.vue b/src/components/FeedPage.vue index d06e8b63..cbfa5e4c 100644 --- a/src/components/FeedPage.vue +++ b/src/components/FeedPage.vue @@ -94,8 +94,13 @@ export default { }, }, mounted() { - this.fetchFeed().then(videos => { - this.videosStore = videos; + this.fetchFeed().then(resp => { + if (resp.error) { + alert(resp.error); + return; + } + + this.videosStore = resp; this.loadMoreVideos(); this.updateWatched(this.videos); }); @@ -118,26 +123,6 @@ export default { window.removeEventListener("scroll", this.handleScroll); }, methods: { - async fetchFeed() { - if (this.authenticated) { - return await this.fetchJson(this.authApiUrl() + "/feed", { - authToken: this.getAuthToken(), - }); - } else { - const channels = this.getUnauthenticatedChannels(); - const split = channels.split(","); - if (split.length > 100) { - return await this.fetchJson(this.authApiUrl() + "/feed/unauthenticated", null, { - method: "POST", - body: JSON.stringify(split), - }); - } else { - return await this.fetchJson(this.authApiUrl() + "/feed/unauthenticated", { - channels: channels, - }); - } - } - }, async loadChannelGroups() { const groups = await this.getChannelGroups(); this.channelGroups.push(...groups); diff --git a/src/components/SubscriptionsPage.vue b/src/components/SubscriptionsPage.vue index 5a2a86f6..cf5624ae 100644 --- a/src/components/SubscriptionsPage.vue +++ b/src/components/SubscriptionsPage.vue @@ -143,6 +143,11 @@ export default { }, mounted() { this.fetchSubscriptions().then(json => { + if (json.error) { + alert(json.error); + return; + } + this.subscriptions = json; this.subscriptions.forEach(subscription => (subscription.subscribed = true)); }); diff --git a/src/main.js b/src/main.js index cb25fcbf..dadce40e 100644 --- a/src/main.js +++ b/src/main.js @@ -204,6 +204,26 @@ const mixin = { } } }, + async fetchFeed() { + if (this.authenticated) { + return await this.fetchJson(this.authApiUrl() + "/feed", { + authToken: this.getAuthToken(), + }); + } else { + const channels = this.getUnauthenticatedChannels(); + const split = channels.split(","); + if (split.length > 100) { + return await this.fetchJson(this.authApiUrl() + "/feed/unauthenticated", null, { + method: "POST", + body: JSON.stringify(split), + }); + } else { + return await this.fetchJson(this.authApiUrl() + "/feed/unauthenticated", { + channels: channels, + }); + } + } + }, /* generate a temporary file and ask the user to download it */ download(text, filename, mimeType) { var file = new Blob([text], { type: mimeType });