mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-19 00:10:39 +08:00
refactor(core): standardize frontend error handling (#10667)
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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`.
|
||||
*
|
||||
|
||||
@@ -6,5 +6,9 @@
|
||||
"outDir": "./dist",
|
||||
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo"
|
||||
},
|
||||
"references": [{ "path": "../debug" }, { "path": "../env" }]
|
||||
"references": [
|
||||
{ "path": "../debug" },
|
||||
{ "path": "../env" },
|
||||
{ "path": "../error" }
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user