Use Retry-After header for rate limited requests in purge room
This commit is contained in:
parent
145160240a
commit
609e4a97c2
1 changed files with 1 additions and 5 deletions
|
|
@ -876,11 +876,7 @@ export default {
|
||||||
const withRetry = (codeBlock) => {
|
const withRetry = (codeBlock) => {
|
||||||
return codeBlock().catch((error) => {
|
return codeBlock().catch((error) => {
|
||||||
if (error && error.errcode == "M_LIMIT_EXCEEDED") {
|
if (error && error.errcode == "M_LIMIT_EXCEEDED") {
|
||||||
var retry = 1000;
|
const retry = error.getRetryAfterMs() ?? 1000;
|
||||||
if (error.data) {
|
|
||||||
const retryIn = error.data.retry_after_ms;
|
|
||||||
retry = Math.max(retry, retryIn ? retryIn : 0);
|
|
||||||
}
|
|
||||||
console.log("Rate limited, retry in", retry);
|
console.log("Rate limited, retry in", retry);
|
||||||
return sleep(retry).then(() => withRetry(codeBlock));
|
return sleep(retry).then(() => withRetry(codeBlock));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue