You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Capture HTTP error response headers & handle Retry-After header (MSC4041) (#4471)
* Include HTTP response headers in MatrixError * Lint * Support MSC4041 / Retry-After header * Fix tests * Remove redundant MatrixError parameter properties They are inherited from HTTPError, so there is no need to mark them as parameter properties. * Comment that retry_after_ms is deprecated * Properly handle colons in XHR header values Also remove the negation in the if-condition for better readability * Improve Retry-After parsing and docstring * Revert ternary operator to if statements for readability * Reuse resolved Headers for Content-Type parsing * Treat empty Content-Type differently from null * Add MatrixError#isRateLimitError This is separate from MatrixError#getRetryAfterMs because it's possible for a rate-limit error to have no Retry-After time, and having separate methods to check each makes that more clear. * Ignore HTTP status code when getting Retry-After because status codes other than 429 may have Retry-After * Catch Retry-After parsing errors * Add test coverage for HTTP error headers * Update license years * Move safe Retry-After lookup to global function so it can more conveniently check if an error is a MatrixError * Lint * Inline Retry-After header value parsing as it is only used in one place and doesn't need to be exported * Update docstrings Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> * Use bare catch Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> * Give HTTPError methods for rate-limit checks and make MatrixError inherit them * Cover undefined errcode in rate-limit check * Update safeGetRetryAfterMs docstring Be explicit that errors that don't look like rate-limiting errors will not pull a retry delay value from the error. * Use rate-limit helper functions in more places * Group the header tests --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
16153e5d82
commit
546047a050
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2023 - 2024 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -34,7 +34,7 @@ import { randomString, secureRandomBase64Url } from "../randomstring.ts";
|
||||
import { EncryptionKeysEventContent } from "./types.ts";
|
||||
import { decodeBase64, encodeUnpaddedBase64 } from "../base64.ts";
|
||||
import { KnownMembership } from "../@types/membership.ts";
|
||||
import { MatrixError } from "../http-api/errors.ts";
|
||||
import { MatrixError, safeGetRetryAfterMs } from "../http-api/errors.ts";
|
||||
import { MatrixEvent } from "../models/event.ts";
|
||||
import { isLivekitFocusActive } from "./LivekitFocus.ts";
|
||||
import { ExperimentalGroupCallRoomMemberState } from "../webrtc/groupCall.ts";
|
||||
@@ -630,7 +630,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
|
||||
this.client.cancelPendingEvent(matrixError.event);
|
||||
}
|
||||
if (this.keysEventUpdateTimeout === undefined) {
|
||||
const resendDelay = matrixError.data?.retry_after_ms ?? 5000;
|
||||
const resendDelay = safeGetRetryAfterMs(matrixError, 5000);
|
||||
logger.warn(`Failed to send m.call.encryption_key, retrying in ${resendDelay}`, error);
|
||||
this.keysEventUpdateTimeout = setTimeout(this.sendEncryptionKeysEvent, resendDelay);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user