From 7077f49e6775b76ea93050aa9b8772ded4a43400 Mon Sep 17 00:00:00 2001 From: DimaZhukovsky Date: Wed, 11 Sep 2024 16:30:21 +0200 Subject: [PATCH] Added checking response code before retry --- src/client.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 55967b8..fdbb779 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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. */ @@ -189,7 +192,12 @@ export class Client { const response = await this.httpClient.request(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()));