From 421f7d185cffdd4f4c632c53a7ba436cb9c774cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Wed, 13 Sep 2023 15:24:25 +0000 Subject: [PATCH] User Error Formatting --- ui/src/components/AdminButton.vue | 14 +++- ui/src/components/DoorMapEditor.vue | 72 +++++++++++------- ui/src/components/calendar/CalendarDoor.vue | 22 +----- ui/src/plugins/advent22.ts | 84 ++++++++++++++++----- 4 files changed, 122 insertions(+), 70 deletions(-) diff --git a/ui/src/components/AdminButton.vue b/ui/src/components/AdminButton.vue index b84149c..80f1846 100644 --- a/ui/src/components/AdminButton.vue +++ b/ui/src/components/AdminButton.vue @@ -48,10 +48,16 @@ export default class extends Vue { this.modal_visible = false; this.$advent22.set_api_auth(username, password); - this.$advent22.api_get("admin/is_admin").then((is_admin) => { - this.$emit("update:modelValue", is_admin); - this.is_busy = false; - }); + this.$advent22 + .api_get("admin/is_admin") + .then((is_admin) => { + this.$emit("update:modelValue", is_admin); + this.is_busy = false; + }) + .catch((error) => { + alert(this.$advent22.format_user_error(error)); + this.is_busy = false; + }); } public on_cancel() { diff --git a/ui/src/components/DoorMapEditor.vue b/ui/src/components/DoorMapEditor.vue index ce278c2..f7d685f 100644 --- a/ui/src/components/DoorMapEditor.vue +++ b/ui/src/components/DoorMapEditor.vue @@ -83,46 +83,58 @@ export default class extends Vue { public loading_doors = false; public saving_doors = false; - private load_doors(): Promise { - return this.$advent22 - .api_get("admin/doors") - .then((data) => { - this.doors.length = 0; + private load_doors(): Promise { + return new Promise((resolve, reject) => { + this.$advent22 + .api_get("admin/doors") + .then((data) => { + this.doors.length = 0; - for (const value of data) { - this.doors.push(Door.load(value)); - } + for (const value of data) { + this.doors.push(Door.load(value)); + } - this.is_loaded = true; - }) - .catch(([reason, endpoint]) => alert(`Fehler: ${reason} in ${endpoint}`)); + this.is_loaded = true; + resolve(data); + }) + .catch(([reason, endpoint]) => { + alert(`Fehler: ${reason} in ${endpoint}`); + reject(); + }); + }); } private save_doors(): Promise { - const data: DoorsSaved = []; + return new Promise((resolve, reject) => { + const data: DoorsSaved = []; - for (const door of this.doors) { - data.push(door.save()); - } + for (const door of this.doors) { + data.push(door.save()); + } - return this.$advent22 - .api_put("admin/doors", data) - .catch((reason) => alert(`Fehler: ${reason} in admin/doors`)); + this.$advent22 + .api_put("admin/doors", data) + .then(resolve) + .catch(([reason, endpoint]) => { + alert(`Fehler: ${reason} in ${endpoint}`); + reject(); + }); + }); } public on_open(): void { this.is_loaded = false; - this.load_doors(); + this.load_doors().catch(() => {}); } public on_download() { if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) { this.loading_doors = true; - this.load_doors().then(() => { - alert("Erfolgeich!"); - this.loading_doors = false; - }); + this.load_doors() + .then(() => alert("Erfolgeich!")) + .catch(() => {}) + .finally(() => (this.loading_doors = false)); } } @@ -137,12 +149,14 @@ export default class extends Vue { if (confirm("Aktuelle Änderungen an den Server schicken?")) { this.saving_doors = true; - this.save_doors().then(() => { - this.load_doors().then(() => { - alert("Erfolgeich!"); - this.saving_doors = false; - }); - }); + this.save_doors() + .then(() => { + this.load_doors() + .then(() => alert("Erfolgeich!")) + .catch(() => {}) + .finally(() => (this.saving_doors = false)); + }) + .catch(() => (this.saving_doors = false)); } } } diff --git a/ui/src/components/calendar/CalendarDoor.vue b/ui/src/components/calendar/CalendarDoor.vue index a453e04..6b94b8f 100644 --- a/ui/src/components/calendar/CalendarDoor.vue +++ b/ui/src/components/calendar/CalendarDoor.vue @@ -4,7 +4,6 @@