fix: retry after a brief delay upon a 429 response
This commit is contained in:
parent
967d6e0e3d
commit
069ba2bc9e
|
@ -507,7 +507,25 @@ function createRpcRequest(url): RpcRequest {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(url, options);
|
let too_many_requests_retries = 5;
|
||||||
|
let res = {};
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
res = await fetch(url, options);
|
||||||
|
if (
|
||||||
|
res.status !== 429 /* Too many requests */ ||
|
||||||
|
too_many_requests_retries === 0
|
||||||
|
) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Server responded with ${res.status} ${res.statusText}. Retrying after brief delay...`,
|
||||||
|
);
|
||||||
|
await sleep(500);
|
||||||
|
too_many_requests_retries -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
const text = await res.text();
|
const text = await res.text();
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
callback(null, text);
|
callback(null, text);
|
||||||
|
|
Loading…
Reference in New Issue