Skip to content

Commit

Permalink
Retry on more 50X status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyphu committed Dec 20, 2023
1 parent 1f62681 commit 3c73e11
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface FetchRequestOptions {
const MAX_RETRY_ATTEMPTS = 3;
const BACKOFF_MULTIPLIER = 1.5;
const MINIMUM_SLEEP_TIME = 500;
const RETRY_STATUS_CODES = [500, 502, 504];

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

Expand Down Expand Up @@ -95,6 +96,11 @@ export default class ApiClient implements HttpClient {
retryAttempts++;
await sleep(this.getSleepTime(retryAttempts));
return makeRequest();

return setTimeout(async () => {
const response = await makeRequest();
return new Promise((resolve) => resolve(response));
})
}

if (!response.ok) {
Expand All @@ -116,7 +122,7 @@ export default class ApiClient implements HttpClient {
return true;
}

if (response?.status == 502) {
if (response != null && RETRY_STATUS_CODES.includes(response.status)) {
return true;
}

Expand Down

0 comments on commit 3c73e11

Please sign in to comment.