File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -188,17 +188,29 @@ export const collections = {
188188 ] ;
189189 // See https://github.com/antfu/fast-npm-meta
190190 const url = `https://npm.antfu.dev/${ packages . join ( '+' ) } ` ;
191- const data = await fetch ( url ) . then ( ( res ) => res . json ( ) ) ;
192- return data . map ( ( pkg : any ) => ( { id : pkg . name , version : pkg . version } ) ) ;
191+ try {
192+ const res = await fetch ( url ) ;
193+ if ( ! res . ok ) return [ ] ;
194+ const data = await res . json ( ) ;
195+ if ( ! Array . isArray ( data ) ) return [ ] ;
196+ return data . map ( ( pkg : any ) => ( { id : pkg . name , version : pkg . version } ) ) ;
197+ } catch {
198+ return [ ] ;
199+ }
193200 } ,
194201 schema : z . object ( { version : z . string ( ) } ) ,
195202 } ) ,
196203 astroContributors : defineCollection ( {
197204 loader : async ( ) => {
198- const { data } = await fetch ( 'https://astro.badg.es/api/v1/top-contributors.json' ) . then (
199- ( res ) => res . json ( )
200- ) ;
201- return data . map ( ( contributor : any ) => ( { id : contributor . username , ...contributor } ) ) ;
205+ try {
206+ const res = await fetch ( 'https://astro.badg.es/api/v1/top-contributors.json' ) ;
207+ if ( ! res . ok ) return [ ] ;
208+ const { data } = await res . json ( ) ;
209+ if ( ! Array . isArray ( data ) ) return [ ] ;
210+ return data . map ( ( contributor : any ) => ( { id : contributor . username , ...contributor } ) ) ;
211+ } catch {
212+ return [ ] ;
213+ }
202214 } ,
203215 schema : z . object ( { avatar_url : z . string ( ) } ) ,
204216 } ) ,
You can’t perform that action at this time.
0 commit comments