Skip to content

Commit

Permalink
feat(http): better handle ECONNRESET errors
Browse files Browse the repository at this point in the history
  • Loading branch information
netlob committed Aug 5, 2024
1 parent 5333a90 commit 3109494
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib/http/HttpManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class HttpClient {
requestConfig.retryAttempt ||= 0;

const isRateLimited = err.response && err.response.status === 429;
const isConnectionReset = (err as AxiosError).code === 'ECONNRESET';

if (isRateLimited) {
if (this.config.logRetry) {
Expand All @@ -136,6 +137,16 @@ export class HttpClient {
await sleep(retryAfter * 1_000);

requestConfig.retryAttempt = 0;
} else if (isConnectionReset) {
await sleep(1_000 * (requestConfig.retryAttempt + 1));

requestConfig.retryAttempt += 1;

if (this.config.debug) {
console.log(
`(${requestConfig.retryAttempt}/${this.maxRetryAttempts}) retry ${requestConfig.url} - ${err}`
);
}
} else {
await sleep(1_000);

Expand Down

0 comments on commit 3109494

Please sign in to comment.