From d0d81510cca3466662643ab1273b79603629381f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Mon, 26 Aug 2024 19:13:08 +0000 Subject: [PATCH] store: catch failure to load from API --- ui/src/lib/store.ts | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/ui/src/lib/store.ts b/ui/src/lib/store.ts index 9b7388f..2bd837f 100644 --- a/ui/src/lib/store.ts +++ b/ui/src/lib/store.ts @@ -67,30 +67,34 @@ export const advent22Store = defineStore({ document.getElementsByTagName("head")[0].appendChild(link); } catch {} - const [is_admin, site_config, background_image, user_doors, next_door] = - await Promise.all([ - this.update_is_admin(), - API.request("user/site_config"), - API.request("user/background_image"), - API.request("user/doors"), - API.request("user/next_door"), - ]); - is_admin; // discard value + try { + const [is_admin, site_config, background_image, user_doors, next_door] = + await Promise.all([ + this.update_is_admin(), + API.request("user/site_config"), + API.request("user/background_image"), + API.request("user/doors"), + API.request("user/next_door"), + ]); + is_admin; // discard value - document.title = site_config.title; + document.title = site_config.title; - if (site_config.subtitle !== "") - document.title += " – " + site_config.subtitle; + if (site_config.subtitle !== "") + document.title += " – " + site_config.subtitle; - this.site_config = site_config; - this.background_image = background_image; + this.site_config = site_config; + this.background_image = background_image; - this.user_doors.length = 0; - for (const door_saved of user_doors) { - this.user_doors.push(Door.load(door_saved)); + this.user_doors.length = 0; + for (const door_saved of user_doors) { + this.user_doors.push(Door.load(door_saved)); + } + + if (next_door !== null) this.next_door_target = Date.now() + next_door; + } catch { + this.background_image = "error"; } - - if (next_door !== null) this.next_door_target = Date.now() + next_door; }, when_initialized(callback: () => void): void {