Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Added checking response code before retry
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaZhukovsky committed Sep 11, 2024
1 parent 5f631ff commit 7077f49
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class ApiError extends Error {
}
}

// We should retry request only in case of timeout or disconnect
const RETRY_CODES = ['ECONNABORTED', 'ECONNREFUSED'];

/**
* Swell API Client.
*/
Expand Down Expand Up @@ -189,7 +192,12 @@ export class Client {
const response = await this.httpClient.request<T>(requestParams);
resolve(transformResponse(response).data);
} catch (error) {
if (operation.retry(error as Error)) {
const code = axios.isAxiosError(error) ? error?.code : null;
if (
code &&
RETRY_CODES.includes(code) &&
operation.retry(error as Error)
) {
return;
}
reject(transformError(operation.mainError()));
Expand Down

0 comments on commit 7077f49

Please sign in to comment.