From 7bf38b0d07efcadc08fefb711dbe663a5f669d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Mon, 9 Mar 2026 14:10:37 +0800 Subject: [PATCH] Add error handling to async calls in AcctMenu Co-Authored-By: Claude Opus 4.6 --- src/components/AccountMenu/AcctMenu.vue | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/components/AccountMenu/AcctMenu.vue b/src/components/AccountMenu/AcctMenu.vue index 5a363f5..779f32c 100644 --- a/src/components/AccountMenu/AcctMenu.vue +++ b/src/components/AccountMenu/AcctMenu.vue @@ -92,18 +92,26 @@ const isAdmin = ref(false); /** Fetches user data and determines if the current user is an admin. */ const getIsAdminValue = async () => { - await loginStore.getUserData(); - loginUserData.value = loginStore.userData; - await acctMgmtStore.getUserDetail(loginUserData.value.username); - isAdmin.value = acctMgmtStore.currentViewingUser.is_admin; + try { + await loginStore.getUserData(); + loginUserData.value = loginStore.userData; + await acctMgmtStore.getUserDetail(loginUserData.value.username); + isAdmin.value = acctMgmtStore.currentViewingUser.is_admin; + } catch (error) { + console.error("Failed to fetch admin status:", error); + } }; /** Navigates to the My Account page. */ const onBtnMyAccountClick = async () => { - acctMgmtStore.closeAcctMenu(); - await acctMgmtStore.getAllUserAccounts(); // in case we haven't fetched yet - await acctMgmtStore.setCurrentViewingUser(loginUserData.value.username); - await router.push("/my-account"); + try { + acctMgmtStore.closeAcctMenu(); + await acctMgmtStore.getAllUserAccounts(); // in case we haven't fetched yet + await acctMgmtStore.setCurrentViewingUser(loginUserData.value.username); + await router.push("/my-account"); + } catch (error) { + console.error("Failed to navigate to My Account:", error); + } }; /**