@@ -31,8 +31,14 @@ const castFetcher = <T, >(fetcher: Fetcher<T, string>) => fetcher;
31
31
type FetcherArray < T extends any [ ] , U extends Key > = { [ K in keyof T ] : Fetcher < T [ K ] , U > } ;
32
32
type ResultArray < T extends any [ ] > = { [ K in keyof T ] : T [ K ] } ;
33
33
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 [ ] > => {
35
35
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
+ }
36
42
// @ts -ignore
37
43
const results = await Promise . all ( fetchers . map ( ( fetcher , index ) => fetcher ( inputs [ index ] ) ) ) ;
38
44
return results as ResultArray < T > ;
@@ -57,7 +63,7 @@ export const useLugReport = () => {
57
63
error,
58
64
isLoading,
59
65
isValidating
60
- } = useSWR ( LUG_SERVERS , liftFetchers ( LUG_SERVERS . map ( ( ) => lugFetcher ) ) )
66
+ } = useSWR ( LUG_SERVERS , liftFetchers ( LUG_SERVERS . map ( ( ) => lugFetcher ) , true ) )
61
67
const mergedData = useMemo ( ( ) => {
62
68
const merged = data ?. map ( ( data ) => data . WorkerStatus ) . reduce ( ( prev , x ) => ( { ...prev , ...x } ) )
63
69
if ( merged !== undefined ) {
@@ -78,7 +84,7 @@ export const useError = (error: any) => {
78
84
color : "red" ,
79
85
title : "出错了" ,
80
86
icon : < IconX /> ,
81
- message : error ,
87
+ message : error . toString ( ) ,
82
88
} )
83
89
}
84
90
} , [ error ] ) ;
0 commit comments