Skip to content

Commit 7b25718

Browse files
bigintChaituVR
authored andcommitted
refactor: simplify retry logic in fetchWithRetry method (#553)
* fix: remove duplicate promisification of Pool and Connection in mysql helper * refactor: simplify retry logic in fetchWithRetry method --------- Co-authored-by: Chaitanya <[email protected]>
1 parent b7ea17c commit 7b25718

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/lib/importer/statement/provider/karmahq.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,22 @@ export default class Karmahq extends Provider {
2020
static readonly ID = 'karmahq';
2121

2222
async fetchWithRetry<T>(fn: () => Promise<T>, retries = 3): Promise<T> {
23-
while (retries > 0) {
24-
try {
25-
const response: Response = await fn();
23+
try {
24+
const response: Response = await fn();
2625

27-
if (!response.ok) {
28-
throw new Error(`Response not ok: ${response.status}`);
29-
}
26+
if (!response.ok) {
27+
throw new Error(`Response not ok: ${response.status}`);
28+
}
3029

31-
return response;
32-
} catch (error) {
33-
console.log(`Error, retrying...`);
34-
if (retries > 0) {
35-
this.fetchWithRetry(fn, retries - 1);
36-
} else {
37-
throw error;
38-
}
30+
return response;
31+
} catch (error) {
32+
if (retries <= 0) {
33+
throw error;
3934
}
35+
36+
console.log(`Error, retrying...`);
37+
return this.fetchWithRetry(fn, retries - 1);
4038
}
41-
throw new Error('Max retries reached');
4239
}
4340

4441
async _fetch() {

0 commit comments

Comments
 (0)