From 578d210f772f86c2b4c5852c043f0708ee284284 Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Fri, 12 Jul 2024 00:19:42 +0200 Subject: [PATCH] Inform user when server can't be reached on login --- src/screens/Login.vue | 4 +++- src/stores/assets.ts | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/screens/Login.vue b/src/screens/Login.vue index f3799a6..cb1b2e2 100644 --- a/src/screens/Login.vue +++ b/src/screens/Login.vue @@ -52,7 +52,9 @@ onMounted(async () => { /** * Fetch assets from the server */ - assetStore.fetchAssets() + if (!await assetStore.fetchAssets()) { + notifications.addNotification({ message: 'Failed to fetch assets, the server may be offline or in maintenance. Please try again later.' }) + } }) async function loginFunc() { diff --git a/src/stores/assets.ts b/src/stores/assets.ts index c9b54ae..35be40b 100644 --- a/src/stores/assets.ts +++ b/src/stores/assets.ts @@ -21,15 +21,17 @@ export const useAssetStore = defineStore('assets', { setObjects(objects: Object[]) { this.objects = objects }, - fetchAssets() { - fetch(config.server_endpoint + '/assets') + async fetchAssets() { + return fetch(config.server_endpoint + '/assets') .then((response) => response.json()) .then((assets) => { - this.setAssets(assets) + this.setAssets(assets); + return true; }) .catch((error) => { - console.error('Error fetching assets:', error) - }) + console.error('Error fetching assets:', error); + return false; + }); } } })