From 4e0777d723ad9cafed5cb69fd0f8f2d12f5d3561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Thu, 12 Jan 2023 13:39:22 +0800 Subject: [PATCH] refactor: output errors on devtools (#928) --- components/account/AccountFollowButton.vue | 9 ++++++--- .../notification/NotificationPreferences.client.vue | 9 ++++++++- components/user/UserSignIn.vue | 4 +++- composables/masto/publish.ts | 3 +++ composables/paginator.ts | 2 ++ composables/users.ts | 12 ++++-------- error.vue | 3 ++- middleware/permalink.global.ts | 4 +++- scripts/avatars.ts | 4 +++- 9 files changed, 34 insertions(+), 16 deletions(-) diff --git a/components/account/AccountFollowButton.vue b/components/account/AccountFollowButton.vue index 5a39eaa0..7b79778e 100644 --- a/components/account/AccountFollowButton.vue +++ b/components/account/AccountFollowButton.vue @@ -19,7 +19,8 @@ async function toggleFollow() { const newRel = await masto.v1.accounts[relationship!.following ? 'follow' : 'unfollow'](account.id) Object.assign(relationship!, newRel) } - catch { + catch (err) { + console.error(err) // TODO error handling relationship!.following = !relationship!.following } @@ -31,7 +32,8 @@ async function unblock() { const newRel = await masto.v1.accounts.unblock(account.id) Object.assign(relationship!, newRel) } - catch { + catch (err) { + console.error(err) // TODO error handling relationship!.blocking = true } @@ -43,7 +45,8 @@ async function unmute() { const newRel = await masto.v1.accounts.unmute(account.id) Object.assign(relationship!, newRel) } - catch { + catch (err) { + console.error(err) // TODO error handling relationship!.muting = true } diff --git a/components/notification/NotificationPreferences.client.vue b/components/notification/NotificationPreferences.client.vue index a0915598..8710c8d4 100644 --- a/components/notification/NotificationPreferences.client.vue +++ b/components/notification/NotificationPreferences.client.vue @@ -49,7 +49,10 @@ const saveSettings = async () => { try { const subscription = await updateSubscription() + } + catch (err) { // todo: handle error + console.error(err) } finally { busy = false @@ -72,7 +75,8 @@ const doSubscribe = async () => { showSubscribeError = true } } - catch { + catch (err) { + console.error(err) subscribeError = t('settings.notifications.push_notifications.subscription_error.request_error') showSubscribeError = true } @@ -91,6 +95,9 @@ const removeSubscription = async () => { try { await unsubscribe() } + catch (err) { + console.error(err) + } finally { busy = false animateRemoveSubscription = false diff --git a/components/user/UserSignIn.vue b/components/user/UserSignIn.vue index e4138ee7..10aa877c 100644 --- a/components/user/UserSignIn.vue +++ b/components/user/UserSignIn.vue @@ -32,7 +32,9 @@ async function oauth() { }, }) } - catch { + catch (err) { + console.error(err) + displayError = true error = true await nextTick() diff --git a/composables/masto/publish.ts b/composables/masto/publish.ts index 13c15940..d34f0da5 100644 --- a/composables/masto/publish.ts +++ b/composables/masto/publish.ts @@ -57,6 +57,9 @@ export const usePublish = (options: { return status } + catch (err) { + console.error(err) + } finally { isSending = false } diff --git a/composables/paginator.ts b/composables/paginator.ts index 6fc2de5b..518e3408 100644 --- a/composables/paginator.ts +++ b/composables/paginator.ts @@ -86,6 +86,8 @@ export function usePaginator( } } catch (e) { + console.error(e) + error.value = e state.value = 'error' } diff --git a/composables/users.ts b/composables/users.ts index 1b44db3f..14a6f4c3 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -140,7 +140,8 @@ async function loginTo(user?: Omit & { account?: mastodon. if (!users.value.some(u => u.server === user.server && u.token === user.token)) users.value.push(user as UserLogin) } - catch { + catch (err) { + console.error(err) await signout() } } @@ -206,7 +207,7 @@ export async function removePushNotificationData(user: UserLogin, fromSWPushMana await subscription.unsubscribe() } catch { - // juts ignore + // just ignore } } } @@ -216,12 +217,7 @@ export async function removePushNotifications(user: UserLogin) { return // unsubscribe push notifications - try { - await useMasto().v1.webPushSubscriptions.remove() - } - catch { - // ignore - } + await useMasto().v1.webPushSubscriptions.remove().catch(() => Promise.resolve()) } export async function signout() { diff --git a/error.vue b/error.vue index 79e965da..897b1d5b 100644 --- a/error.vue +++ b/error.vue @@ -24,7 +24,8 @@ const reload = async () => { await masto.loginTo(currentUser.value) clearError({ redirect: currentUser.value ? '/home' : `/${currentServer.value}/public/local` }) } - catch { + catch (err) { + console.error(err) state.value = 'error' } } diff --git a/middleware/permalink.global.ts b/middleware/permalink.global.ts index 79099c99..d4b9b0ef 100644 --- a/middleware/permalink.global.ts +++ b/middleware/permalink.global.ts @@ -62,7 +62,9 @@ export default defineNuxtRouteMiddleware(async (to, from) => { if (accounts[0]) return getAccountRoute(accounts[0]) } - catch {} + catch (err) { + console.error(err) + } return '/home' }) diff --git a/scripts/avatars.ts b/scripts/avatars.ts index 708e586c..03a387dd 100644 --- a/scripts/avatars.ts +++ b/scripts/avatars.ts @@ -16,7 +16,9 @@ async function download(url: string, fileName: string) { const image = await $fetch(url, { responseType: 'arrayBuffer' }) await fs.writeFile(fileName, Buffer.from(image)) } - catch {} + catch (err) { + console.error(err) + } } async function fetchAvatars() {