diff --git a/spec/integ/matrix-client-syncing.spec.ts b/spec/integ/matrix-client-syncing.spec.ts index 3609e8a0f3d..418e2d16add 100644 --- a/spec/integ/matrix-client-syncing.spec.ts +++ b/spec/integ/matrix-client-syncing.spec.ts @@ -274,6 +274,16 @@ describe("MatrixClient syncing", () => { expect(fires).toBe(1); }); + + it("should work when all network calls fail", async () => { + httpBackend!.expectedRequests = []; + httpBackend!.when("GET", "").fail(0, new Error("CORS or something")); + const prom = client!.startClient(); + await Promise.all([ + expect(prom).resolves.toBeUndefined(), + httpBackend!.flushAllExpected(), + ]); + }); }); describe("initial sync", () => { diff --git a/src/client.ts b/src/client.ts index 67d56f7b942..4c380ec4138 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1193,16 +1193,18 @@ export class MatrixClient extends TypedEventEmitter} The server /versions response */ - public getVersions(): Promise { + public async getVersions(): Promise { if (this.serverVersionsPromise) { return this.serverVersionsPromise; } @@ -6724,13 +6726,20 @@ export class MatrixClient extends TypedEventEmitter { + ).catch(e => { // Need to unset this if it fails, otherwise we'll never retry this.serverVersionsPromise = undefined; // but rethrow the exception to anything that was waiting throw e; }); + const serverVersions = await this.serverVersionsPromise; + this.canSupport = await buildFeatureSupportMap(serverVersions); + + // We can set flag values to use their stable or unstable version + const support = this.canSupport.get(Feature.ThreadUnreadNotifications); + UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(support === ServerSupport.Unstable); + return this.serverVersionsPromise; }