fix: retry after a brief delay upon a 429 response

This commit is contained in:
Michael Vines 2020-08-17 15:33:58 -07:00
parent 967d6e0e3d
commit 069ba2bc9e
1 changed files with 19 additions and 1 deletions

View File

@ -507,7 +507,25 @@ function createRpcRequest(url): RpcRequest {
};
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();
if (res.ok) {
callback(null, text);