Skip to content

Commit 0e2f81e

Browse files
nexy7574Gnuxie
andauthored
Fix the individual request rate-limit (#694)
* Fix the individual request rate-limit This fixes the first problem raised in #693 --------- Signed-off-by: nexy7574 <[email protected]> Co-authored-by: Gnuxie <[email protected]>
1 parent 2300b1e commit 0e2f81e

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/utils.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,18 @@ function patchMatrixClientForRetry() {
492492
return cb(...result);
493493
} catch (err) {
494494
// Need to retry.
495-
let retryAfterMs = attempt * attempt * REQUEST_RETRY_BASE_DURATION_MS;
496-
if ("retry_after_ms" in err) {
497-
try {
498-
retryAfterMs = Number.parseInt(err.retry_after_ms, 10);
499-
} catch (ex) {
500-
// Use default value.
495+
const retryAfterMs = (() => {
496+
if (err instanceof MatrixError && err.retryAfterMs !== undefined) {
497+
return err.retryAfterMs;
498+
} else {
499+
LogService.error(
500+
"Draupnir.client",
501+
"Unable to extract retry_after_ms from error, using fallback to create retry duration",
502+
err
503+
);
504+
return attempt * attempt * REQUEST_RETRY_BASE_DURATION_MS;
501505
}
502-
}
506+
})();
503507
LogService.debug(
504508
"Draupnir.client",
505509
`Waiting ${retryAfterMs}ms before retrying ${params.method} ${params.uri}`

0 commit comments

Comments
 (0)