From 60d5e732d94aa5faa434879de638bb54ac16a997 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 1 Oct 2020 18:58:13 -0600 Subject: [PATCH] Wrap canEncryptToAllUsers in a try/catch to handle server errors Fixes https://github.com/vector-im/element-web/issues/12266 --- src/createRoom.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/createRoom.ts b/src/createRoom.ts index 078e54f5d8..34eb65df4e 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -275,12 +275,17 @@ export async function _waitForMember(client: MatrixClient, roomId: string, userI * can encrypt to. */ export async function canEncryptToAllUsers(client: MatrixClient, userIds: string[]) { - const usersDeviceMap = await client.downloadKeys(userIds); - // { "@user:host": { "DEVICE": {...}, ... }, ... } - return Object.values(usersDeviceMap).every((userDevices) => - // { "DEVICE": {...}, ... } - Object.keys(userDevices).length > 0, - ); + try { + const usersDeviceMap = await client.downloadKeys(userIds); + // { "@user:host": { "DEVICE": {...}, ... }, ... } + return Object.values(usersDeviceMap).every((userDevices) => + // { "DEVICE": {...}, ... } + Object.keys(userDevices).length > 0, + ); + } catch (e) { + console.error("Error determining if it's possible to encrypt to all users: ", e); + return false; // assume not + } } export async function ensureDMExists(client: MatrixClient, userId: string): Promise {