File tree Expand file tree Collapse file tree
packages/get-github-info/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @changesets/get-github-info " : patch
3+ ---
4+
5+ Improve error messages when fail to fetch data from GitHub
Original file line number Diff line number Diff line change @@ -101,17 +101,31 @@ const GHDataLoader = new DataLoader(async (requests: RequestData[]) => {
101101 repos [ repo ] . push ( data ) ;
102102 } ) ;
103103
104- const data = await fetch ( GITHUB_GRAPHQL_URL , {
105- method : "POST" ,
106- headers : {
107- Authorization : `Token ${ GITHUB_TOKEN } ` ,
108- } ,
109- body : JSON . stringify ( { query : makeQuery ( repos ) } ) ,
110- } ) . then ( ( x : any ) => x . json ( ) ) ;
104+ let fetchResponse ;
105+ try {
106+ fetchResponse = await fetch ( GITHUB_GRAPHQL_URL , {
107+ method : "POST" ,
108+ headers : {
109+ Authorization : `Token ${ GITHUB_TOKEN } ` ,
110+ } ,
111+ body : JSON . stringify ( { query : makeQuery ( repos ) } ) ,
112+ } ) ;
113+ } catch ( e : any ) {
114+ throw new Error (
115+ `An error occurred when fetching data from GitHub\n${ e . message } `
116+ ) ;
117+ }
118+
119+ let data ;
120+ try {
121+ data = await fetchResponse . json ( ) ;
122+ } catch ( e : any ) {
123+ throw new Error ( `Failed to parse data from GitHub\n${ e . message } ` ) ;
124+ }
111125
112126 if ( data . errors ) {
113127 throw new Error (
114- `An error occurred when fetching data from GitHub\n${ JSON . stringify (
128+ `Fetched data from GitHub returned errors \n${ JSON . stringify (
115129 data . errors ,
116130 null ,
117131 2
@@ -122,9 +136,7 @@ const GHDataLoader = new DataLoader(async (requests: RequestData[]) => {
122136 // this is mainly for the case where there's an authentication problem
123137 if ( ! data . data ) {
124138 throw new Error (
125- `An error occurred when fetching data from GitHub\n${ JSON . stringify (
126- data
127- ) } `
139+ `Fetched data from GitHub has missing data\n${ JSON . stringify ( data ) } `
128140 ) ;
129141 }
130142
You can’t perform that action at this time.
0 commit comments