@@ -130,12 +130,18 @@ const getData = async (url, options) => {
130
130
. then ( response => response . json ( ) )
131
131
. then ( data => {
132
132
if ( data . error_code ) {
133
- console . warn (
134
- `Error ${ data . error_code } : ${ data . error_message } . Details: ${ JSON . stringify ( data . errors ) } `
135
- ) ;
136
- if ( data . error_code >= 500 ) {
133
+ if ( data . error_code === 141 ) {
134
+ console . warn (
135
+ `Error ${ data . error_code } : ${ data . error_message } . Details: ${ JSON . stringify ( data . errors ) } `
136
+ ) ;
137
+ console . info ( "Retrying... Please wait..." )
138
+ }
139
+ else if ( data . error_code >= 500 ) {
137
140
throw new Error ( `Server error: ${ data . error_code } ` ) ;
138
141
}
142
+ else {
143
+ console . error ( "data" ) ;
144
+ }
139
145
reject ( data ) ;
140
146
} else {
141
147
if ( data . items ) {
@@ -253,7 +259,7 @@ const getSyncData = async (url, config, query, responseKey, aggregatedResponse =
253
259
254
260
// Handle pagination
255
261
if ( response . pagination_token ) {
256
- return handlePagination ( url , config , response . pagination_token , responseKey , aggregatedResponse ) ;
262
+ await handlePagination ( url , config , response . pagination_token , responseKey , aggregatedResponse ) ;
257
263
}
258
264
259
265
// Handle sync tokens for final sync call
@@ -288,7 +294,7 @@ const processSyncTokens = async (url, config, aggregatedResponse, syncToken) =>
288
294
await waitFor ( delay ) ;
289
295
} else {
290
296
throw new Error (
291
- `Failed to fetch sync data after ${ config . httpRetries } retry attempts due to sync token error.`
297
+ `Failed after ${ config . httpRetries } retries due to a sync token error.`
292
298
) ;
293
299
}
294
300
}
@@ -309,11 +315,11 @@ const handlePagination = async (url, config, paginationToken, responseKey, aggre
309
315
return await getSyncData ( url , config , { pagination_token : paginationToken } , responseKey , aggregatedResponse , 0 ) ;
310
316
} catch ( error ) {
311
317
if ( retries < config . httpRetries ) {
312
- const retryDelay = 2 ** retries * 1000 ;
318
+ const retryDelay = Math . min ( 2 ** retries * 1000 , 30000 ) ;
313
319
await waitFor ( retryDelay ) ;
314
320
return await handlePagination ( url , config , paginationToken , responseKey , aggregatedResponse , retries + 1 ) ;
315
321
}
316
- throw new Error ( `Failed to fetch sync data after ${ config . httpRetries } retries due to pagination error.` ) ;
322
+ throw new Error ( `Failed after ${ config . httpRetries } retries due to a pagination token error.` ) ;
317
323
}
318
324
} ;
319
325
0 commit comments