refactor(core): standardize frontend error handling (#10667)

This commit is contained in:
forehalo
2025-03-06 13:10:18 +00:00
parent 2e86bfffae
commit e02fb4fa94
70 changed files with 495 additions and 480 deletions

View File

@@ -8,5 +8,6 @@ export {
mapInto,
onComplete,
onStart,
smartRetry,
} from './ops';
export { useEnsureLiveData, useLiveData } from './react';

View File

@@ -1,3 +1,4 @@
import { UserFriendlyError } from '@affine/error';
import {
catchError,
connect,
@@ -144,6 +145,32 @@ export function backoffRetry<T>({
);
}
export function smartRetry<T>({
count = 3,
delay = 200,
maxDelay = 15000,
}: {
count?: number;
delay?: number;
maxDelay?: number;
} = {}) {
return (obs$: Observable<T>) =>
obs$.pipe(
backoffRetry({
when: UserFriendlyError.isNetworkError,
count: Infinity,
delay,
maxDelay,
}),
backoffRetry({
when: UserFriendlyError.notNetworkError,
count,
delay,
maxDelay,
})
);
}
/**
* An operator that combines `exhaustMap` and `switchMap`.
*