From 1487932c1dddfe3035cabaab1153d6a6b244ffeb Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Fri, 5 May 2023 17:34:43 +0000 Subject: [PATCH] fix: Handle failure when fetching user preferences (#2069) --- composables/users.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/composables/users.ts b/composables/users.ts index 5ffc16ec..36db7d8b 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -169,7 +169,7 @@ export async function loginTo(masto: ElkMasto, user: Overwrite() +const accountPreferencesMap = new Map>() /** * @returns `true` when user ticked the preference to always expand posts with content warnings @@ -193,9 +193,20 @@ export function getHideMediaByDefault(account: mastodon.v1.AccountCredentials) { } export async function fetchAccountInfo(client: mastodon.Client, server: string) { + // Try to fetch user preferences if the backend supports it. + const fetchPrefs = async (): Promise> => { + try { + return await client.v1.preferences.fetch() + } + catch (e) { + console.warn(`Cannot fetch preferences: ${e}`) + return {} + } + } + const [account, preferences] = await Promise.all([ client.v1.accounts.verifyCredentials(), - client.v1.preferences.fetch(), + fetchPrefs(), ]) if (!account.acct.includes('@'))