Wrap await in try/catch to fix sign-in in tauri builds (#349)
Fixes #342
This commit is contained in:
@ -98,12 +98,16 @@ async function getUser(context: UserContext) {
|
|||||||
}
|
}
|
||||||
if (!context.token && '__TAURI__' in window) throw 'not log in'
|
if (!context.token && '__TAURI__' in window) throw 'not log in'
|
||||||
if (context.token) headers['Authorization'] = `Bearer ${context.token}`
|
if (context.token) headers['Authorization'] = `Bearer ${context.token}`
|
||||||
const response = await fetch(url, {
|
try {
|
||||||
method: 'GET',
|
const response = await fetch(url, {
|
||||||
credentials: 'include',
|
method: 'GET',
|
||||||
headers,
|
credentials: 'include',
|
||||||
})
|
headers,
|
||||||
const user = await response.json()
|
})
|
||||||
if ('error_code' in user) throw new Error(user.message)
|
const user = await response.json()
|
||||||
return user
|
if ('error_code' in user) throw new Error(user.message)
|
||||||
|
return user
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user