Wrap await in try/catch to fix sign-in in tauri builds (#349)

Fixes #342
This commit is contained in:
Pierre Jacquier
2023-08-29 21:45:40 -04:00
committed by GitHub
parent 853389ba22
commit 2b1a556b81

View File

@ -98,12 +98,16 @@ async function getUser(context: UserContext) {
}
if (!context.token && '__TAURI__' in window) throw 'not log in'
if (context.token) headers['Authorization'] = `Bearer ${context.token}`
const response = await fetch(url, {
method: 'GET',
credentials: 'include',
headers,
})
const user = await response.json()
if ('error_code' in user) throw new Error(user.message)
return user
try {
const response = await fetch(url, {
method: 'GET',
credentials: 'include',
headers,
})
const user = await response.json()
if ('error_code' in user) throw new Error(user.message)
return user
} catch (e) {
console.error(e)
}
}