@@ -15,7 +15,7 @@ export type MetaData = {
15
15
16
16
// until dedicated endpoint been provided - fetch one by one
17
17
export const useGetStreamMetadata = ( ) => {
18
- const [ isLoading , setLoading ] = useState < boolean > ( false ) ;
18
+ const [ isLoading , setLoading ] = useState < boolean > ( true ) ;
19
19
const [ error , setError ] = useState < boolean > ( false ) ;
20
20
const [ metaData , setMetadata ] = useState < MetaData | null > ( null ) ;
21
21
const [ userRoles ] = useAppStore ( ( store ) => store . userRoles ) ;
@@ -24,25 +24,54 @@ export const useGetStreamMetadata = () => {
24
24
async ( streams : string [ ] ) => {
25
25
if ( ! userRoles ) return ;
26
26
setLoading ( true ) ;
27
+ let encounteredError = false ;
27
28
try {
28
29
// stats
29
30
const allStatsReqs = streams . map ( ( stream ) => getLogStreamStats ( stream ) ) ;
30
- const allStatsRes = await Promise . all ( allStatsReqs ) ;
31
+ const statsResults = await Promise . allSettled ( allStatsReqs ) ;
31
32
33
+ // Notify errors for stats
34
+ statsResults . forEach ( ( result , index ) => {
35
+ if ( result . status === 'rejected' ) {
36
+ encounteredError = true ;
37
+ notifyError ( {
38
+ message : `Failed to fetch stats for stream: ${ streams [ index ] } ` ,
39
+ } ) ;
40
+ }
41
+ } ) ;
32
42
// retention
33
43
const streamsWithSettingsAccess = _ . filter ( streams , ( stream ) =>
34
44
_ . includes ( getStreamsSepcificAccess ( userRoles , stream ) , 'StreamSettings' ) ,
35
45
) ;
36
- const allretentionReqs = streamsWithSettingsAccess . map ( ( stream ) => getLogStreamRetention ( stream ) ) ;
37
- const allretentionRes = await Promise . all ( allretentionReqs ) ;
46
+ const allRetentionReqs = streamsWithSettingsAccess . map ( ( stream ) => getLogStreamRetention ( stream ) ) ;
47
+ const retentionResults = await Promise . allSettled ( allRetentionReqs ) ;
48
+
49
+ // Notify errors for retention
50
+ retentionResults . forEach ( ( result , index ) => {
51
+ if ( result . status === 'rejected' ) {
52
+ encounteredError = true ;
53
+ notifyError ( {
54
+ message : `Failed to fetch retention for stream: ${ streamsWithSettingsAccess [ index ] } ` ,
55
+ } ) ;
56
+ }
57
+ } ) ;
38
58
59
+ // Combine results
39
60
const metadata = streams . reduce ( ( acc , stream , index ) => {
61
+ const statsResult = statsResults [ index ] ;
62
+ const retentionResult = retentionResults . find ( ( _ , idx ) => streamsWithSettingsAccess [ idx ] === stream ) ;
63
+
40
64
return {
41
65
...acc ,
42
- [ stream ] : { stats : allStatsRes [ index ] ?. data || { } , retention : allretentionRes [ index ] ?. data || [ ] } ,
66
+ [ stream ] : {
67
+ stats : statsResult ?. status === 'fulfilled' ? statsResult . value . data : { } ,
68
+ retention : retentionResult ?. status === 'fulfilled' ? retentionResult . value . data : [ ] ,
69
+ } ,
43
70
} ;
44
71
} , { } ) ;
72
+
45
73
setMetadata ( metadata ) ;
74
+ setError ( encounteredError ) ;
46
75
} catch {
47
76
setError ( true ) ;
48
77
setMetadata ( null ) ;
0 commit comments