Skip to content

Commit

Permalink
🐛 Properly catch lazy fetch profile error
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Dec 11, 2024
1 parent ef67d8f commit 8f126a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
7 changes: 1 addition & 6 deletions pages/nft-book-store/user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,7 @@ onMounted(async () => {
loadCommissionHistory(),
refreshUserLikerInfo(),
refreshStripeConnectStatus(),
userStore.lazyFetchBookUserProfile().catch((e: Error) => {
if (e.message !== 'USER_NOT_FOUND') {
// eslint-disable-next-line no-console
console.error(e)
}
})
userStore.lazyFetchBookUserProfile()
])
if (isStripeConnectReady.value) { await loadPayoutHistory() }
})
Expand Down
19 changes: 11 additions & 8 deletions stores/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ export const useUserStore = defineStore('user', () => {
return bookUser.value
}

function lazyFetchBookUserProfile () {
async function lazyFetchBookUserProfile () {
if (bookUser.value) {
return bookUser.value
}
return fetchBookUserProfile()
try {
const user = await fetchBookUserProfile()
return user
} catch (e: unknown) {
if ((e as Error).message !== 'USER_NOT_FOUND') {
// eslint-disable-next-line no-console
console.error(e)
}
}
}

async function updateBookUserProfile (payload: any) {
Expand Down Expand Up @@ -90,12 +98,7 @@ export const useUserStore = defineStore('user', () => {
watch(isAuthenticated, () => {
if (isAuthenticated.value) {
lazyFetchUserLikerInfo()
lazyFetchBookUserProfile().catch((e: Error) => {
if (e.message !== 'USER_NOT_FOUND') {
// eslint-disable-next-line no-console
console.error(e)
}
})
lazyFetchBookUserProfile()
} else {
bookUser.value = null
}
Expand Down

0 comments on commit 8f126a1

Please sign in to comment.