This repository was archived by the owner on Oct 10, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed
Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -119,27 +119,26 @@ exports.generateMethod = method => {
119119 // Adapted from:
120120 // https://github.com/netlify/open-api/blob/master/go/porcelain/http/http.go
121121
122- const MAX_RETRY = 5
122+ const MAX_RETRY = 10
123123 const DEFAULT_RETRY_DELAY = 5000 //ms
124124
125125 for ( let index = 0 ; index <= MAX_RETRY ; index ++ ) {
126+ debug ( 'Rate limit attempt ' + index + ' for ' + path )
126127 const response = await makeRequest ( )
127- if ( http . STATUS_CODES [ response . status ] !== 'Too Many Requests' || index === MAX_RETRY ) {
128+ if ( index === MAX_RETRY ) throw new Error ( 'Rate limit retry exhausted, aborting ' )
129+ if ( http . STATUS_CODES [ response . status ] !== 'Too Many Requests' ) {
128130 return response
129131 } else {
130132 debug ( `Rate limited, retrying` )
131133 try {
132134 const rateLimitReset = response . headers . get ( 'X-RateLimit-Reset' )
133- debug ( 'rateLimitReset: %O' , rateLimitReset )
134135 const resetTime = Number . parseInt ( rateLimitReset )
135136 if ( ! existy ( resetTime ) ) {
136137 debug ( 'Issue getting resetTime: %O' , resetTime )
137138 throw new Error ( 'Header missing reset time' )
138139 }
139- debug ( `resetTime: ${ resetTime } ` )
140140 const now = unixNow ( )
141- debug ( `unixNow(): ${ now } ` )
142- const sleepTime = ( resetTime - now < 0 ? 0 : resetTime - now ) * 1000
141+ const sleepTime = ( ( resetTime - now < 0 ? 0 : resetTime - now ) + 1 ) * 1000 // minimum 1 second
143142 debug ( `sleeping for ${ sleepTime } ms` )
144143 await sleep ( sleepTime )
145144 } catch ( e ) {
You can’t perform that action at this time.
0 commit comments