Skip to content

Commit e357d91

Browse files
chore: incorporated feedback for warning message & retry delays
1 parent 7ca9a3a commit e357d91

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/fetch.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,18 @@ const getData = async (url, options) => {
130130
.then(response => response.json())
131131
.then(data => {
132132
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) {
137140
throw new Error(`Server error: ${data.error_code}`);
138141
}
142+
else {
143+
console.error("data");
144+
}
139145
reject(data);
140146
} else {
141147
if (data.items) {
@@ -253,7 +259,7 @@ const getSyncData = async (url, config, query, responseKey, aggregatedResponse =
253259

254260
// Handle pagination
255261
if (response.pagination_token) {
256-
return handlePagination(url, config, response.pagination_token, responseKey, aggregatedResponse);
262+
await handlePagination(url, config, response.pagination_token, responseKey, aggregatedResponse);
257263
}
258264

259265
// Handle sync tokens for final sync call
@@ -288,7 +294,7 @@ const processSyncTokens = async (url, config, aggregatedResponse, syncToken) =>
288294
await waitFor(delay);
289295
} else {
290296
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.`
292298
);
293299
}
294300
}
@@ -309,11 +315,11 @@ const handlePagination = async (url, config, paginationToken, responseKey, aggre
309315
return await getSyncData(url, config, { pagination_token: paginationToken }, responseKey, aggregatedResponse, 0);
310316
} catch (error) {
311317
if (retries < config.httpRetries) {
312-
const retryDelay = 2 ** retries * 1000;
318+
const retryDelay = Math.min(2 ** retries * 1000, 30000);
313319
await waitFor(retryDelay);
314320
return await handlePagination(url, config, paginationToken, responseKey, aggregatedResponse, retries + 1);
315321
}
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.`);
317323
}
318324
};
319325

0 commit comments

Comments
 (0)