@@ -15,7 +15,7 @@ export type MetaData = {
1515
1616// until dedicated endpoint been provided - fetch one by one
1717export const useGetStreamMetadata = ( ) => {
18- const [ isLoading , setLoading ] = useState < boolean > ( false ) ;
18+ const [ isLoading , setLoading ] = useState < boolean > ( true ) ;
1919 const [ error , setError ] = useState < boolean > ( false ) ;
2020 const [ metaData , setMetadata ] = useState < MetaData | null > ( null ) ;
2121 const [ userRoles ] = useAppStore ( ( store ) => store . userRoles ) ;
@@ -24,25 +24,54 @@ export const useGetStreamMetadata = () => {
2424 async ( streams : string [ ] ) => {
2525 if ( ! userRoles ) return ;
2626 setLoading ( true ) ;
27+ let encounteredError = false ;
2728 try {
2829 // stats
2930 const allStatsReqs = streams . map ( ( stream ) => getLogStreamStats ( stream ) ) ;
30- const allStatsRes = await Promise . all ( allStatsReqs ) ;
31+ const statsResults = await Promise . allSettled ( allStatsReqs ) ;
3132
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+ } ) ;
3242 // retention
3343 const streamsWithSettingsAccess = _ . filter ( streams , ( stream ) =>
3444 _ . includes ( getStreamsSepcificAccess ( userRoles , stream ) , 'StreamSettings' ) ,
3545 ) ;
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+ } ) ;
3858
59+ // Combine results
3960 const metadata = streams . reduce ( ( acc , stream , index ) => {
61+ const statsResult = statsResults [ index ] ;
62+ const retentionResult = retentionResults . find ( ( _ , idx ) => streamsWithSettingsAccess [ idx ] === stream ) ;
63+
4064 return {
4165 ...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+ } ,
4370 } ;
4471 } , { } ) ;
72+
4573 setMetadata ( metadata ) ;
74+ setError ( encounteredError ) ;
4675 } catch {
4776 setError ( true ) ;
4877 setMetadata ( null ) ;
0 commit comments