diff --git a/frontend/src/api/createFeed.ts b/frontend/src/api/createFeed.ts index 9c4c4aa..2c89049 100644 --- a/frontend/src/api/createFeed.ts +++ b/frontend/src/api/createFeed.ts @@ -1,22 +1,24 @@ import { Module } from "../model/module.ts"; export async function createIndividualFeed(modules: Module[]): Promise { - let token = ""; - - await fetch("/api/createFeed", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(modules), - }) - .then((response) => { - return response.json(); - }) - .then((response) => { - token = response; + try { + const response = await fetch("/api/createFeed", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(modules), }); - return token; + + if (response.status === 429 || response.status === 500 || response.status != 200) { + return Promise.reject(response.statusText); + } + + return await response.json(); + } catch (error) { + // Catch possible errors and return an unfilled promise + return Promise.reject(error); + } } interface FeedResponse { diff --git a/frontend/src/components/RenameModules.vue b/frontend/src/components/RenameModules.vue index df6361b..17f2eee 100644 --- a/frontend/src/components/RenameModules.vue +++ b/frontend/src/components/RenameModules.vue @@ -8,6 +8,7 @@ import ModuleTemplateDialog from "./ModuleTemplateDialog.vue"; import { onlyWhitespace } from "../helpers/strings.ts"; import { useI18n } from "vue-i18n"; import { Module } from "@/model/module.ts"; +import { useToast } from "primevue/usetoast"; const { t } = useI18n({ useScope: "global" }); const store = moduleStore(); @@ -33,10 +34,26 @@ const columns = computed(() => [ { field: "Reminder", header: t("renameModules.reminder") }, ]); +const toast = useToast(); + async function finalStep() { - const token: string = await createIndividualFeed(store.getAllModules()); - tokenStore().setToken(token); - await router.push("/calendar-link"); + const createFeed: Promise= createIndividualFeed(store.getAllModules()); + + // Check if createFeed Promise is resolved + createFeed.then(async (token: string) => { + tokenStore().setToken(token); + await router.push("/calendar-link"); + }); + + // if createFeed Promise is rejected + createFeed.catch(() => { + toast.add({ + severity: "error", + summary: t("renameModules.error"), + detail: t("renameModules.TooManyRequests"), + life: 3000, + }); + }); } diff --git a/frontend/src/i18n/translations/de.json b/frontend/src/i18n/translations/de.json index cef6dc4..f073849 100644 --- a/frontend/src/i18n/translations/de.json +++ b/frontend/src/i18n/translations/de.json @@ -110,7 +110,9 @@ "reminder": "Erinnerung", "enableAllNotifications": "Alle Benachrichtigungen aktivieren", "subTitle": "Konfigurieren Sie die ausgewählten Module nach Ihren Wünschen.", - "nextStep": "Speichern" + "nextStep": "Speichern", + "error": "Fehler", + "TooManyRequests": "Zu viele Anfragen um einen Kalender zu erstellen. Bitte versuchen Sie es später erneut." }, "moduleTemplateDialog": { "explanationOne": "Hier können Module nach Wunsch umbenannt werden, welche dann als Anzeigename im Kalender dargestellt werden.", diff --git a/frontend/src/i18n/translations/en.json b/frontend/src/i18n/translations/en.json index ac33f7a..d082f39 100644 --- a/frontend/src/i18n/translations/en.json +++ b/frontend/src/i18n/translations/en.json @@ -110,7 +110,9 @@ "reminder": "reminder", "enableAllNotifications": "enable all notifications", "subTitle": "configure your selected modules to your liking", - "nextStep": "save" + "nextStep": "save", + "error": "error", + "TooManyRequests": "too many requests for creating a calendar in a short time" }, "moduleTemplateDialog": { "explanationOne": "Here you can rename your modules to your liking. This will be the name of the event in your calendar.",