mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 01:26:37 +08: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);
|
logger.error('Failed to fetch session', res.statusText);
|
||||||
return { user: null };
|
throw new Error('Failed to fetch session');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('Failed to fetch session', e);
|
logger.error('Failed to fetch session', e);
|
||||||
return { user: null };
|
throw new Error('Failed to fetch session');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSession(): 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 {
|
return {
|
||||||
user: data?.user,
|
user: data?.user,
|
||||||
|
|||||||
Reference in New Issue
Block a user