@@ -154,22 +154,29 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
154154 } ;
155155 console . log ( `Getting submission from LeetCode, offset ${ offset } ` ) ;
156156
157- const getSubmissions = async ( retryCount = 0 ) => {
157+ const getSubmissions = async ( maxRetries , retryCount = 0 ) => {
158158 try {
159159 const response = await axios . get ( 'https://leetcode.com/api/submissions/' , config ) ;
160160 return response ;
161161 } catch ( exception ) {
162- if ( retryCount > 3 ) {
162+ if ( retryCount >= maxRetries ) {
163+ console . log ( exception ) ;
163164 throw exception ;
164165 }
165- console . log ( 'Error fetching submissions, retrying in ' + 2 ** retryCount + ' seconds...' ) ;
166+ console . log ( 'Error fetching submissions, retrying in ' + 3 ** retryCount + ' seconds...' ) ;
166167 // There's a rate limit on LeetCode API, so wait with backoff before retrying.
167- await delay ( 2 ** retryCount * 1000 ) ;
168- return getSubmissions ( retryCount + 1 ) ;
168+ await delay ( 3 ** retryCount * 1000 ) ;
169+ return getSubmissions ( maxRetries , retryCount + 1 ) ;
169170 }
170171 } ;
171-
172- response = await getSubmissions ( ) ;
172+ // On the first attempt, there should be no rate limiting issues, so we fail immediately in case
173+ // the tokens are configured incorrectly.
174+ const maxRetries = ( response === null ) ? 0 : 5 ;
175+ if ( response !== null ) {
176+ // Add a 1 second delay before all requests after the initial request.
177+ await delay ( 1000 ) ;
178+ }
179+ response = await getSubmissions ( maxRetries ) ;
173180 if ( ! addToSubmissions ( response , lastTimestamp , filterDuplicateSecs , submissions_dict , submissions ) ) {
174181 break ;
175182 }
0 commit comments