mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 08:38:34 +00:00
fix(core): catch auth error (#6128)
This commit is contained in:
@@ -38,15 +38,25 @@ export async function getSession(
|
||||
}
|
||||
|
||||
logger.error('Failed to fetch session', res.statusText);
|
||||
return { user: null };
|
||||
throw new Error('Failed to fetch session');
|
||||
} catch (e) {
|
||||
logger.error('Failed to fetch session', e);
|
||||
return { user: null };
|
||||
throw new Error('Failed to fetch session');
|
||||
}
|
||||
}
|
||||
|
||||
export function useSession(): Session {
|
||||
const { data, mutate, isLoading } = useSWR('session', () => getSession());
|
||||
const {
|
||||
data,
|
||||
mutate,
|
||||
isLoading,
|
||||
error: _error, // use error here to avoid uncaught error in the console
|
||||
} = useSWR('session', () => getSession(), {
|
||||
errorRetryCount: 3,
|
||||
errorRetryInterval: 500,
|
||||
shouldRetryOnError: true,
|
||||
suspense: false,
|
||||
});
|
||||
|
||||
return {
|
||||
user: data?.user,
|
||||
|
||||
Reference in New Issue
Block a user