From d821783201577fe368c7a289ace177e203a9af61 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Oct 2024 18:12:50 +0300 Subject: [PATCH] fix: support non-200 RPC error --- packages/providers/src/fetch_json.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/providers/src/fetch_json.ts b/packages/providers/src/fetch_json.ts index fe83961208..67a9caef8b 100644 --- a/packages/providers/src/fetch_json.ts +++ b/packages/providers/src/fetch_json.ts @@ -9,7 +9,7 @@ const retryConfig = { numOfAttempts: RETRY_NUMBER, timeMultiple: BACKOFF_MULTIPLIER, retry: (e: ProviderError) => { - if ([503, 408].includes(e.cause)) { + if ([500, 408].includes(e.cause)) { return true; } @@ -60,10 +60,12 @@ export async function fetchJsonRpc(url: string, json: JsonRpcRequest, headers: o throw new ProviderError(await res.text(), { cause: status }); } - if (status === 503) { - throw new ProviderError(`${url} unavailable`, { cause: status }); + if (status === 500) { + throw new ProviderError(`Internal server error`, { cause: status }); } else if (status === 408) { - throw new ProviderError('Unused connection', { cause: status }); + throw new ProviderError('Timeout error', { cause: status }); + } else if (status === 400) { + throw new ProviderError('Request validation error', { cause: status }); } return res;