Skip to content

Commit a5361db

Browse files
fix: do not crash when any server is offline (#94)
1 parent f518fe4 commit a5361db

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,34 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
16-
- name: Use Node.js 20.x
16+
17+
- uses: pnpm/action-setup@v4
18+
name: Install pnpm
19+
with:
20+
version: 9
21+
run_install: false
22+
23+
- name: Install Node.js
1724
uses: actions/setup-node@v4
1825
with:
1926
node-version: 20
27+
cache: 'pnpm'
28+
29+
- name: Get pnpm store directory
30+
shell: bash
31+
run: |
32+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
33+
34+
- uses: actions/cache@v4
35+
name: Setup pnpm cache
36+
with:
37+
path: ${{ env.STORE_PATH }}
38+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
39+
restore-keys: |
40+
${{ runner.os }}-pnpm-store-
41+
2042
- name: Install dependencies
2143
run: pnpm install
44+
2245
- name: Build
2346
run: pnpm build

src/rpcs.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ const castFetcher = <T, >(fetcher: Fetcher<T, string>) => fetcher;
3131
type FetcherArray<T extends any[], U extends Key> = { [K in keyof T]: Fetcher<T[K], U> };
3232
type ResultArray<T extends any[]> = { [K in keyof T]: T[K] };
3333

34-
const liftFetchers = <T extends any[], U extends Key>(fetchers: FetcherArray<T, U>): Fetcher<ResultArray<T>, U[]> => {
34+
const liftFetchers = <T extends any[], U extends Key>(fetchers: FetcherArray<T, U>, ignoreError: boolean): Fetcher<ResultArray<T>, U[]> => {
3535
return async (inputs: U[]) => {
36+
if (ignoreError) {
37+
// @ts-ignore
38+
const tryResults = await Promise.all(fetchers.map((fetcher, index) => fetcher(inputs[index]).catch(e => e)));
39+
const results = tryResults.filter((x) => !(x instanceof Error));
40+
return results as ResultArray<T>;
41+
}
3642
// @ts-ignore
3743
const results = await Promise.all(fetchers.map((fetcher, index) => fetcher(inputs[index])));
3844
return results as ResultArray<T>;
@@ -57,7 +63,7 @@ export const useLugReport = () => {
5763
error,
5864
isLoading,
5965
isValidating
60-
} = useSWR(LUG_SERVERS, liftFetchers(LUG_SERVERS.map(() => lugFetcher)))
66+
} = useSWR(LUG_SERVERS, liftFetchers(LUG_SERVERS.map(() => lugFetcher), true))
6167
const mergedData = useMemo(() => {
6268
const merged = data?.map((data) => data.WorkerStatus).reduce((prev, x) => ({...prev, ...x}))
6369
if (merged !== undefined) {
@@ -78,7 +84,7 @@ export const useError = (error: any) => {
7884
color: "red",
7985
title: "出错了",
8086
icon: <IconX/>,
81-
message: error,
87+
message: error.toString(),
8288
})
8389
}
8490
}, [error]);

0 commit comments

Comments
 (0)