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
+1
View File
@@ -13,6 +13,7 @@
"dependencies": {
"@affine/debug": "workspace:*",
"@affine/env": "workspace:*",
"@affine/error": "workspace:*",
"@affine/templates": "workspace:*",
"@datastructures-js/binary-search-tree": "^5.3.2",
"@preact/signals-core": "^1.8.0",
@@ -8,5 +8,6 @@ export {
mapInto,
onComplete,
onStart,
smartRetry,
} from './ops';
export { useEnsureLiveData, useLiveData } from './react';
+27
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`.
*
+5 -1
View File
@@ -6,5 +6,9 @@
"outDir": "./dist",
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo"
},
"references": [{ "path": "../debug" }, { "path": "../env" }]
"references": [
{ "path": "../debug" },
{ "path": "../env" },
{ "path": "../error" }
]
}