Skip to content

Commit 735f190

Browse files
committed
Merge #151: Show error notifications when API calls return an error
07ffcea feat: [#99] show error notifications when API calls return an error (Jose Celano) Pull request description: In most cases the application was failing silently. Top commit has no ACKs. Tree-SHA512: b542d92b2b79e00c0a9191124ce7abd475c3a4a670551163c31d06c2f2405963735741eed86137c15c523d198e90feae1b9273ea08894739f47ce0a4dae8853f
2 parents 6294798 + 07ffcea commit 735f190

File tree

11 files changed

+127
-21
lines changed

11 files changed

+127
-21
lines changed

components/authentication/AuthenticationForm.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ type Form = {
5656
confirm_password: string
5757
}
5858
59-
const config = useRuntimeConfig();
6059
const rest = useRestApi();
6160
const authModalOpen = useAuthenticationModal();
6261
const settings = useSettings();
@@ -120,8 +119,8 @@ function login () {
120119
notify({
121120
group: "error",
122121
title: "Error",
123-
text: err.message
124-
}, 4000); // 4s
122+
text: `Login failed. ${err.message}.`
123+
}, 10000);
125124
});
126125
}
127126
@@ -143,8 +142,8 @@ function signup () {
143142
notify({
144143
group: "error",
145144
title: "Error",
146-
text: err.message
147-
}, 4000); // 4s
145+
text: `Registration failed. ${err.message}.`
146+
}, 10000);
148147
});
149148
}
150149
</script>

components/torrent/TorrentActionCard.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
import { LinkIcon, CalendarIcon, CircleStackIcon, UserCircleIcon, HashtagIcon, TagIcon } from "@heroicons/vue/24/solid";
151151
import { PropType } from "vue";
152152
import { TorrentResponse } from "torrust-index-types-lib";
153+
import { notify } from "notiwind-ts";
153154
import {
154155
fileSize,
155156
downloadTorrent,
@@ -199,6 +200,13 @@ function deleteTorrent () {
199200
rest.value.torrent.deleteTorrent(props.torrent.info_hash)
200201
.then(() => {
201202
emit("deleted");
203+
})
204+
.catch((err) => {
205+
notify({
206+
group: "error",
207+
title: "Error",
208+
text: `Trying to delete the torrent. ${err.message}.`
209+
}, 10000);
202210
});
203211
}
204212
</script>

components/torrent/TorrentListTorrentDetails.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
<script setup lang="ts">
1818
import { Ref } from "vue";
1919
import { TorrentResponse } from "torrust-index-types-lib";
20-
import { useRuntimeConfig } from "#app";
20+
import { notify } from "notiwind-ts";
2121
import { onMounted, ref, useRestApi } from "#imports";
2222
23-
const config = useRuntimeConfig();
2423
const rest = useRestApi();
2524
2625
const torrent: Ref<TorrentResponse> = ref(null);
@@ -36,6 +35,13 @@ onMounted(() => {
3635
rest.value.torrent.getTorrentInfo(props.infoHash)
3736
.then((data) => {
3837
torrent.value = data;
38+
})
39+
.catch((err) => {
40+
notify({
41+
group: "error",
42+
title: "Error",
43+
text: `Trying to get the torrent information. ${err.message}.`
44+
}, 10000);
3945
});
4046
});
4147
</script>

composables/states.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PublicSettings, Category, TokenResponse, TorrentTag } from "torrust-index-types-lib";
22
import { Rest } from "torrust-index-api-lib";
33
import { useRuntimeConfig, useState } from "#app";
4+
import { notify } from "notiwind-ts";
45

56
export const useRestApi = () => useState<Rest>("rest-api", () => new Rest(useRuntimeConfig().public.apiBase));
67
export const useCategories = () => useState<Array<Category>>("categories", () => new Array<Category>());
@@ -13,20 +14,41 @@ export function getSettings () {
1314
useRestApi().value.settings.getPublicSettings()
1415
.then((publicSettings) => {
1516
useSettings().value = publicSettings;
17+
})
18+
.catch((err) => {
19+
notify({
20+
group: "error",
21+
title: "Error",
22+
text: `Trying to get public settings. ${err.message}.`
23+
}, 10000);
1624
});
1725
}
1826

1927
export function getCategories () {
2028
useRestApi().value.category.getCategories()
2129
.then((res) => {
2230
useCategories().value = res;
31+
})
32+
.catch((err) => {
33+
notify({
34+
group: "error",
35+
title: "Error",
36+
text: `Trying to get categories. ${err.message}.`
37+
}, 10000);
2338
});
2439
}
2540

2641
export function getTags () {
2742
useRestApi().value.tag.getTags()
2843
.then((res) => {
2944
useTags().value = res;
45+
})
46+
.catch((err) => {
47+
notify({
48+
group: "error",
49+
title: "Error",
50+
text: `Trying to get tags. ${err.message}.`
51+
}, 10000);
3052
});
3153
}
3254

@@ -37,6 +59,13 @@ export async function loginUser (login: string, password: string) {
3759
})
3860
.then((user) => {
3961
useUser().value = user;
62+
})
63+
.catch((err) => {
64+
notify({
65+
group: "error",
66+
title: "Error",
67+
text: `Trying to login. ${err.message}.`
68+
}, 10000);
4069
});
4170
}
4271

@@ -54,5 +83,12 @@ export async function getUser () {
5483
return await useRestApi().value.user.renewToken()
5584
.then((user) => {
5685
useUser().value = user;
86+
})
87+
.catch((err) => {
88+
notify({
89+
group: "error",
90+
title: "Error",
91+
text: `Trying to get user info. ${err.message}.`
92+
}, 10000);
5793
});
5894
}

pages/admin/settings.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
<script setup lang="ts">
3131
import { Ref } from "vue";
3232
import { Settings } from "torrust-index-types-lib";
33-
import { getSettings, onMounted, ref, useRestApi, useRoute, watch } from "#imports";
33+
import { notify } from "notiwind-ts";
34+
import { onMounted, ref, useRestApi } from "#imports";
3435
3536
const tabs = [
3637
"backend",
@@ -50,6 +51,13 @@ function getAdminSettings () {
5051
rest.value.settings.getSettings()
5152
.then((v) => {
5253
settings.value = v;
54+
})
55+
.catch((err) => {
56+
notify({
57+
group: "error",
58+
title: "Error",
59+
text: `Trying to get the backend settings. ${err.message}.`
60+
}, 10000);
5361
});
5462
}
5563

pages/admin/settings/categories.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
2-
<div class="mx-auto flex flex-col gap-2 max-w-md">
2+
<div class="flex flex-col max-w-md gap-2 mx-auto">
33
<div class="flex flex-col gap-2">
44
<template v-for="category in categories">
5-
<div class="p-2 flex justify-between bg-base-100 rounded">
5+
<div class="flex justify-between p-2 rounded bg-base-100">
66
<span class="text-base-content">{{ category.name }} ({{ category.num_torrents }})</span>
77
<button class="text-error-content hover:text-error" @click="deleteCategory(category.name)">
88
Delete
@@ -11,7 +11,7 @@
1111
</template>
1212
</div>
1313
<div class="flex gap-2">
14-
<input v-model="newCategory" class="input input-bordered w-full" type="text">
14+
<input v-model="newCategory" class="w-full input input-bordered" type="text">
1515
<button class="btn btn-primary" :class="{ 'loading': addingCategory }" :disabled="addingCategory || !newCategory" @click="addCategory">
1616
Add category
1717
</button>
@@ -21,6 +21,7 @@
2121

2222
<script setup lang="ts">
2323
import { ref } from "vue";
24+
import { notify } from "notiwind-ts";
2425
import { getCategories, useCategories, useRestApi } from "#imports";
2526
2627
const categories = useCategories();
@@ -37,6 +38,13 @@ function addCategory () {
3738
.then(() => {
3839
getCategories();
3940
})
41+
.catch((err) => {
42+
notify({
43+
group: "error",
44+
title: "Error",
45+
text: `Trying to add the category. ${err.message}.`
46+
}, 10000);
47+
})
4048
.finally(() => {
4149
addingCategory.value = false;
4250
});
@@ -48,6 +56,13 @@ function deleteCategory (category: string) {
4856
rest.category.deleteCategory(category)
4957
.then(() => {
5058
getCategories();
59+
})
60+
.catch((err) => {
61+
notify({
62+
group: "error",
63+
title: "Error",
64+
text: `Trying to delete the category. ${err.message}.`
65+
}, 10000);
5166
});
5267
}
5368
}

pages/admin/settings/tags.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
<script setup lang="ts">
2323
import { ref } from "vue";
2424
import { TorrentTag } from "torrust-index-types-lib";
25-
import { computed, getTags, useRestApi, useTags } from "#imports";
25+
import { notify } from "notiwind-ts";
26+
import { getTags, useRestApi, useTags } from "#imports";
2627
2728
const tags = useTags();
2829
const rest = useRestApi().value;
@@ -38,6 +39,13 @@ function addTag () {
3839
.then(() => {
3940
getTags();
4041
})
42+
.catch((err) => {
43+
notify({
44+
group: "error",
45+
title: "Error",
46+
text: `Trying to add the tag. ${err.message}.`
47+
}, 10000);
48+
})
4149
.finally(() => {
4250
addingTag.value = false;
4351
});
@@ -49,6 +57,13 @@ function deleteTag (tag: TorrentTag) {
4957
rest.tag.deleteTag(tag.tag_id)
5058
.then(() => {
5159
getTags();
60+
})
61+
.catch((err) => {
62+
notify({
63+
group: "error",
64+
title: "Error",
65+
text: `Trying to delete the tag. ${err.message}.`
66+
}, 10000);
5267
});
5368
}
5469
}

pages/torrent/[infoHash].vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ import { ChevronLeftIcon } from "@heroicons/vue/24/solid";
4242
import { Ref } from "vue";
4343
import { TorrentResponse } from "torrust-index-types-lib";
4444
import { useRoute, useRuntimeConfig } from "#app";
45+
import { notify } from "notiwind-ts";
4546
import TorrentActionCard from "~/components/torrent/TorrentActionCard.vue";
4647
import TorrentDescriptionTab from "~/components/torrent/TorrentDescriptionTab.vue";
4748
import TorrentFilesTab from "~/components/torrent/TorrentFilesTab.vue";
4849
import TorrentTrackersTab from "~/components/torrent/TorrentTrackersTab.vue";
4950
import { navigateTo, onMounted, ref, useRestApi } from "#imports";
5051
51-
const config = useRuntimeConfig();
5252
const route = useRoute();
5353
const rest = useRestApi().value;
5454
@@ -72,8 +72,13 @@ function getTorrentFromApi (infoHash: string) {
7272
.then((data) => {
7373
torrent.value = data;
7474
})
75-
.catch(() => {
75+
.catch((err) => {
7676
loadingTorrent.value = false;
77+
notify({
78+
group: "error",
79+
title: "Error",
80+
text: `Trying to get the torrent information. ${err.message}.`
81+
}, 10000);
7782
});
7883
7984
// TODO: Set torrent title in URL.

pages/torrent/edit/[infoHash].vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ function getTorrentFromApi (infoHash: string) {
148148
}
149149
});
150150
})
151+
.catch((err) => {
152+
loadingTorrent.value = false;
153+
notify({
154+
group: "error",
155+
title: "Error",
156+
text: `Trying to get the torrent info. ${err.message}.`
157+
}, 10000);
158+
})
151159
.finally(() => {
152160
loadingTorrent.value = false;
153161
});
@@ -182,11 +190,12 @@ function submitForm () {
182190
navigateTo(`/torrent/${infoHash}`, { replace: true });
183191
})
184192
.catch((err) => {
193+
loadingTorrent.value = false;
185194
notify({
186195
group: "error",
187196
title: "Error",
188-
text: err.message
189-
}, 4000); // 4s
197+
text: `Trying to update torrent info. ${err.message}.`
198+
}, 10000);
190199
})
191200
.finally(() => {
192201
updatingTorrent.value = false;

pages/torrents.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import { useRuntimeConfig, useRoute, useRouter } from "nuxt/app";
6464
import { TorrentListing } from "torrust-index-types-lib";
6565
import { Ref } from "vue";
66+
import { notify } from "notiwind-ts";
6667
import { computed, onMounted, ref, useTags, watch } from "#imports";
6768
import { useCategories, useRestApi } from "~/composables/states";
6869
import { TorrustSelectOption } from "~/components/TorrustSelect.vue";
@@ -77,7 +78,6 @@ const sortingOptions: Array<TorrustSelectOption> = [
7778
7879
const route = useRoute();
7980
const router = useRouter();
80-
const config = useRuntimeConfig();
8181
const categories = useCategories();
8282
const tags = useTags();
8383
const rest = useRestApi();
@@ -147,6 +147,13 @@ function loadTorrents () {
147147
.then((v) => {
148148
torrentsTotal.value = v.total;
149149
torrents.value = v.results;
150+
})
151+
.catch((err) => {
152+
notify({
153+
group: "error",
154+
title: "Error",
155+
text: `Trying to get the information for the torrents. ${err.message}.`
156+
}, 10000);
150157
});
151158
}
152159
</script>

0 commit comments

Comments
 (0)