mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-09-16 15:52:35 +00:00
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 <git@nexy7574.co.uk> Co-authored-by: Gnuxie <50846879+Gnuxie@users.noreply.github.com>
This commit is contained in:
+11
-7
@@ -492,14 +492,18 @@ function patchMatrixClientForRetry() {
|
||||
return cb(...result);
|
||||
} catch (err) {
|
||||
// Need to retry.
|
||||
let retryAfterMs = attempt * attempt * REQUEST_RETRY_BASE_DURATION_MS;
|
||||
if ("retry_after_ms" in err) {
|
||||
try {
|
||||
retryAfterMs = Number.parseInt(err.retry_after_ms, 10);
|
||||
} catch (ex) {
|
||||
// Use default value.
|
||||
const retryAfterMs = (() => {
|
||||
if (err instanceof MatrixError && err.retryAfterMs !== undefined) {
|
||||
return err.retryAfterMs;
|
||||
} else {
|
||||
LogService.error(
|
||||
"Draupnir.client",
|
||||
"Unable to extract retry_after_ms from error, using fallback to create retry duration",
|
||||
err
|
||||
);
|
||||
return attempt * attempt * REQUEST_RETRY_BASE_DURATION_MS;
|
||||
}
|
||||
}
|
||||
})();
|
||||
LogService.debug(
|
||||
"Draupnir.client",
|
||||
`Waiting ${retryAfterMs}ms before retrying ${params.method} ${params.uri}`
|
||||
|
||||
Reference in New Issue
Block a user