From 0be6c4209f56c0595bf66e217b7ac01444981b99 Mon Sep 17 00:00:00 2001 From: Den <41162202+denbite@users.noreply.github.com> Date: Tue, 28 Nov 2023 13:32:24 +0200 Subject: [PATCH] feat: Retry RPC requests on 408 HTTP error (#1205) --- .changeset/healthy-bees-shout.md | 5 +++++ packages/providers/src/fetch_json.ts | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 .changeset/healthy-bees-shout.md diff --git a/.changeset/healthy-bees-shout.md b/.changeset/healthy-bees-shout.md new file mode 100644 index 0000000000..9ba24588aa --- /dev/null +++ b/.changeset/healthy-bees-shout.md @@ -0,0 +1,5 @@ +--- +"@near-js/providers": patch +--- + +retry RPC request on 408 HTTP error diff --git a/packages/providers/src/fetch_json.ts b/packages/providers/src/fetch_json.ts index bef1a029dc..57ee7a9766 100644 --- a/packages/providers/src/fetch_json.ts +++ b/packages/providers/src/fetch_json.ts @@ -38,6 +38,9 @@ export async function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, js if (response.status === 503) { logWarning(`Retrying HTTP request for ${connectionInfo.url} as it's not available now`); return null; + } else if (response.status === 408) { + logWarning(`Retrying HTTP request for ${connectionInfo.url} as the previous connection was unused for some time`); + return null; } throw createError(response.status, await response.text()); }