@@ -31,12 +31,45 @@ async function getLatestVolta(authToken: string): Promise<string> {
3131 } ;
3232 }
3333
34- const response = await http . getJson < { name : string } > ( url , headers ) ;
35- if ( ! response . result ) {
34+ try {
35+ const response = await http . getJson < { name : string } > ( url , headers ) ;
36+ if ( ! response . result ) {
37+ throw new Error ( `volta-cli/action: Could not download latest release from ${ url } ` ) ;
38+ }
39+
40+ return semver . clean ( response . result . name ) as string ;
41+ } catch ( error : unknown ) {
42+ if (
43+ error instanceof hc . HttpClientError &&
44+ ( error . statusCode === 403 || error . statusCode === 429 )
45+ ) {
46+ core . info (
47+ `Received HTTP status code ${ error . statusCode } . This usually indicates the rate limit has been exceeded`
48+ ) ;
49+
50+ return await getLatestVoltaFromVoltaSH ( ) ;
51+ } else {
52+ throw error ;
53+ }
54+ }
55+ }
56+
57+ async function getLatestVoltaFromVoltaSH ( ) : Promise < string > {
58+ const url = 'https://volta.sh/latest-version' ;
59+
60+ core . info ( `Falling back to download from ${ url } ` ) ;
61+
62+ const http = new hc . HttpClient ( 'volta-cli/action' , [ ] , {
63+ allowRetries : true ,
64+ maxRetries : 3 ,
65+ } ) ;
66+
67+ const response = await http . get ( url ) ;
68+ if ( response . message . statusCode !== 200 ) {
3669 throw new Error ( `volta-cli/action: Could not download latest release from ${ url } ` ) ;
3770 }
3871
39- return semver . clean ( response . result . name ) as string ;
72+ return semver . clean ( await response . readBody ( ) ) as string ;
4073}
4174
4275function voltaVersionHasSetup ( version : string ) : boolean {
0 commit comments