mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-25 05:49:13 +02:00
feat:#19 added toast for too many requests
This commit is contained in:
@@ -1,22 +1,24 @@
|
|||||||
import { Module } from "../model/module.ts";
|
import { Module } from "../model/module.ts";
|
||||||
|
|
||||||
export async function createIndividualFeed(modules: Module[]): Promise<string> {
|
export async function createIndividualFeed(modules: Module[]): Promise<string> {
|
||||||
let token = "";
|
try {
|
||||||
|
const response = await fetch("/api/createFeed", {
|
||||||
await fetch("/api/createFeed", {
|
method: "POST",
|
||||||
method: "POST",
|
headers: {
|
||||||
headers: {
|
"Content-Type": "application/json",
|
||||||
"Content-Type": "application/json",
|
},
|
||||||
},
|
body: JSON.stringify(modules),
|
||||||
body: JSON.stringify(modules),
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
token = response;
|
|
||||||
});
|
});
|
||||||
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 {
|
interface FeedResponse {
|
||||||
|
@@ -8,6 +8,7 @@ import ModuleTemplateDialog from "./ModuleTemplateDialog.vue";
|
|||||||
import { onlyWhitespace } from "../helpers/strings.ts";
|
import { onlyWhitespace } from "../helpers/strings.ts";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { Module } from "@/model/module.ts";
|
import { Module } from "@/model/module.ts";
|
||||||
|
import { useToast } from "primevue/usetoast";
|
||||||
const { t } = useI18n({ useScope: "global" });
|
const { t } = useI18n({ useScope: "global" });
|
||||||
|
|
||||||
const store = moduleStore();
|
const store = moduleStore();
|
||||||
@@ -33,10 +34,26 @@ const columns = computed(() => [
|
|||||||
{ field: "Reminder", header: t("renameModules.reminder") },
|
{ field: "Reminder", header: t("renameModules.reminder") },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const toast = useToast();
|
||||||
|
|
||||||
async function finalStep() {
|
async function finalStep() {
|
||||||
const token: string = await createIndividualFeed(store.getAllModules());
|
const createFeed: Promise<string>= createIndividualFeed(store.getAllModules());
|
||||||
tokenStore().setToken(token);
|
|
||||||
await router.push("/calendar-link");
|
// 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,
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@@ -110,7 +110,9 @@
|
|||||||
"reminder": "Erinnerung",
|
"reminder": "Erinnerung",
|
||||||
"enableAllNotifications": "Alle Benachrichtigungen aktivieren",
|
"enableAllNotifications": "Alle Benachrichtigungen aktivieren",
|
||||||
"subTitle": "Konfigurieren Sie die ausgewählten Module nach Ihren Wünschen.",
|
"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": {
|
"moduleTemplateDialog": {
|
||||||
"explanationOne": "Hier können Module nach Wunsch umbenannt werden, welche dann als Anzeigename im Kalender dargestellt werden.",
|
"explanationOne": "Hier können Module nach Wunsch umbenannt werden, welche dann als Anzeigename im Kalender dargestellt werden.",
|
||||||
|
@@ -110,7 +110,9 @@
|
|||||||
"reminder": "reminder",
|
"reminder": "reminder",
|
||||||
"enableAllNotifications": "enable all notifications",
|
"enableAllNotifications": "enable all notifications",
|
||||||
"subTitle": "configure your selected modules to your liking",
|
"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": {
|
"moduleTemplateDialog": {
|
||||||
"explanationOne": "Here you can rename your modules to your liking. This will be the name of the event in your calendar.",
|
"explanationOne": "Here you can rename your modules to your liking. This will be the name of the event in your calendar.",
|
||||||
|
Reference in New Issue
Block a user