@@ -9,28 +9,38 @@ type ApiResponseType = {
99} ;
1010
1111export async function GET ( ) {
12- const [ chainsWithServices , allChains ] = await Promise . all ( [
13- fetch ( "https://api.thirdweb.com/v1/chains/services" , {
12+ const chainsWithServicesResponse = await fetch (
13+ "https://api.thirdweb.com/v1/chains/services" ,
14+ {
1415 headers : {
1516 "Content-Type" : "application/json" ,
1617 } ,
17- } )
18- . then ( ( res ) => res . json ( ) as Promise < ApiResponseType > )
19- . catch ( ( error ) => {
20- console . error ( error ) ;
21- return { data : { } as ApiResponseType [ "data" ] } ;
22- } ) ,
23- fetch ( "https://api.thirdweb.com/v1/chains" , {
24- headers : {
25- "Content-Type" : "application/json" ,
26- } ,
27- } )
28- . then ( ( res ) => res . json ( ) as Promise < { data : ChainMetadata [ ] } > )
29- . catch ( ( error ) => {
30- console . error ( error ) ;
31- return { data : [ ] as ChainMetadata [ ] } ;
32- } ) ,
33- ] ) ;
18+ } ,
19+ ) ;
20+
21+ if ( ! chainsWithServicesResponse . ok ) {
22+ throw new Error (
23+ `Failed to fetch chains with services ${ chainsWithServicesResponse . status } - ${ chainsWithServicesResponse . statusText } ` ,
24+ ) ;
25+ }
26+
27+ const allChainsResponse = await fetch ( "https://api.thirdweb.com/v1/chains" , {
28+ headers : {
29+ "Content-Type" : "application/json" ,
30+ } ,
31+ } ) ;
32+
33+ if ( ! allChainsResponse . ok ) {
34+ throw new Error (
35+ `Failed to fetch all chains ${ allChainsResponse . status } - ${ allChainsResponse . statusText } ` ,
36+ ) ;
37+ }
38+
39+ const chainsWithServices =
40+ ( await chainsWithServicesResponse . json ( ) ) as ApiResponseType ;
41+ const allChains = ( await allChainsResponse . json ( ) ) as {
42+ data : ChainMetadata [ ] ;
43+ } ;
3444
3545 const aaChains = Object . entries ( chainsWithServices . data )
3646 . filter ( ( [ , services ] ) =>
0 commit comments