mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
fix(core): handle the getSession network error properly (#4909)
If network offline or API error happens, the `session` returned by the `useSession` hook will be null, so we can't assume it is not null. There should be following changes: 1. create a page in ErrorBoundary to let the user refetch the session. 2. The `SessionProvider` stop to pull the new session once the session is null, we need to figure out a way to pull the new session when the network is back or the user click the refetch button.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
export abstract class RecoverableError extends Error {
|
||||
protected ttl = 3;
|
||||
|
||||
canRetry(): boolean {
|
||||
return this.ttl > 0;
|
||||
}
|
||||
|
||||
abstract retry(): void;
|
||||
}
|
||||
|
||||
// the first session request failed after login or signup succeed.
|
||||
// should give a hint to the user to refetch the session.
|
||||
export class SessionFetchErrorRightAfterLoginOrSignUp extends RecoverableError {
|
||||
constructor(
|
||||
message: string,
|
||||
private readonly onRetry: () => void
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
retry(): void {
|
||||
if (this.ttl <= 0) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.onRetry();
|
||||
} catch (e) {
|
||||
console.error('Retry error', e);
|
||||
} finally {
|
||||
this.ttl--;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user