store: catch failure to load from API

This commit is contained in:
Jörn-Michael Miehe 2024-08-26 19:13:08 +00:00
parent af5abc7c8f
commit d0d81510cc

View file

@ -67,30 +67,34 @@ export const advent22Store = defineStore({
document.getElementsByTagName("head")[0].appendChild(link); document.getElementsByTagName("head")[0].appendChild(link);
} catch {} } catch {}
const [is_admin, site_config, background_image, user_doors, next_door] = try {
await Promise.all([ const [is_admin, site_config, background_image, user_doors, next_door] =
this.update_is_admin(), await Promise.all([
API.request<SiteConfigModel>("user/site_config"), this.update_is_admin(),
API.request<ImageData>("user/background_image"), API.request<SiteConfigModel>("user/site_config"),
API.request<DoorSaved[]>("user/doors"), API.request<ImageData>("user/background_image"),
API.request<number | null>("user/next_door"), API.request<DoorSaved[]>("user/doors"),
]); API.request<number | null>("user/next_door"),
is_admin; // discard value ]);
is_admin; // discard value
document.title = site_config.title; document.title = site_config.title;
if (site_config.subtitle !== "") if (site_config.subtitle !== "")
document.title += " " + site_config.subtitle; document.title += " " + site_config.subtitle;
this.site_config = site_config; this.site_config = site_config;
this.background_image = background_image; this.background_image = background_image;
this.user_doors.length = 0; this.user_doors.length = 0;
for (const door_saved of user_doors) { for (const door_saved of user_doors) {
this.user_doors.push(Door.load(door_saved)); 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 { when_initialized(callback: () => void): void {