Skip to content

Commit

Permalink
feat: Retry RPC requests on 408 HTTP error (#1205)
Browse files Browse the repository at this point in the history
  • Loading branch information
denbite authored Nov 28, 2023
1 parent 0f764ee commit 0be6c42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-bees-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@near-js/providers": patch
---

retry RPC request on 408 HTTP error
3 changes: 3 additions & 0 deletions packages/providers/src/fetch_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 0be6c42

Please sign in to comment.