diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index 9a2ae6c97..4756544f3 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -417,7 +417,7 @@ describe("MatrixClient", function () { ]); }); - it("should fallback to unstable endpoint when no support for stable endpoint", async () => { + it("should fallback to unstable endpoint when stable endpoint 404s", async () => { await assertRequestsMade([ { prefix: ClientPrefix.V1, @@ -433,6 +433,22 @@ describe("MatrixClient", function () { ]); }); + it("should fallback to unstable endpoint when stable endpoint 405s", async () => { + await assertRequestsMade([ + { + prefix: ClientPrefix.V1, + error: { + httpStatus: 405, + errcode: "M_UNRECOGNIZED", + }, + }, + { + prefix: unstableMSC3030Prefix, + data: { event_id: eventId }, + }, + ]); + }); + it("should not fallback to unstable endpoint when stable endpoint returns an error", async () => { await assertRequestsMade( [ diff --git a/src/client.ts b/src/client.ts index e36ef7c41..7ec959299 100644 --- a/src/client.ts +++ b/src/client.ts @@ -9391,7 +9391,10 @@ export class MatrixClient extends TypedEventEmittererr).httpStatus === 400 || // This the correct standard status code for an unsupported // endpoint according to MSC3743. - (err).httpStatus === 404) + (err).httpStatus === 404 || + // This the correct standard status code for an invalid + // method according to MSC3743. + (err).httpStatus === 405) ) { return await this.http.authedRequest(Method.Get, path, queryParams, undefined, { prefix: "/_matrix/client/unstable/org.matrix.msc3030",