[Backport staging] Catch server versions API call exception when starting the client (#2832)

Co-authored-by: Germain <germains@element.io>
This commit is contained in:
Michael Telatynski
2022-11-01 09:01:52 +00:00
committed by GitHub
parent 7d7803380c
commit fcdd8c93f4
2 changed files with 29 additions and 10 deletions
+10
View File
@@ -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", () => {
+19 -10
View File
@@ -1192,15 +1192,17 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
this.syncApi.stop();
}
const serverVersions = await this.getVersions();
this.canSupport = await buildFeatureSupportMap(serverVersions);
try {
await this.getVersions();
const support = this.canSupport.get(Feature.ThreadUnreadNotifications);
UNREAD_THREAD_NOTIFICATIONS.setPreferUnstable(support === ServerSupport.Unstable);
const { threads, list } = await this.doesServerSupportThread();
Thread.setServerSideSupport(threads);
Thread.setServerSideListSupport(list);
// This should be done with `canSupport`
// TODO: https://github.com/vector-im/element-web/issues/23643
const { threads, list } = await this.doesServerSupportThread();
Thread.setServerSideSupport(threads);
Thread.setServerSideListSupport(list);
} catch (e) {
logger.error("Can't fetch server versions, continuing to initialise sync, this will be retried later", e);
}
// shallow-copy the opts dict before modifying and storing it
this.clientOpts = Object.assign({}, opts) as IStoredClientOpts;
@@ -6518,7 +6520,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* unstable APIs it supports
* @return {Promise<object>} The server /versions response
*/
public getVersions(): Promise<IServerVersions> {
public async getVersions(): Promise<IServerVersions> {
if (this.serverVersionsPromise) {
return this.serverVersionsPromise;
}
@@ -6530,13 +6532,20 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
{
prefix: '',
},
).catch((e: Error) => {
).catch(e => {
// Need to unset this if it fails, otherwise we'll never retry
this.serverVersionsPromise = null;
// 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;
}