mirror of https://github.com/vector-im/riot-web
`shieldStatusForRoom`: guard against client shutdown (#11957)
If `shieldStatusForRoom` races against a logout operation, then some of the (many) crypto operations that it does can fail. Catch the error and handle it gracefully.pull/28788/head^2
parent
926907309a
commit
328de4e9c8
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
|
import { ClientStoppedError, MatrixClient, Room } from "matrix-js-sdk/src/matrix";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
|
||||||
import DMRoomMap from "./DMRoomMap";
|
import DMRoomMap from "./DMRoomMap";
|
||||||
|
@ -32,6 +32,7 @@ export async function shieldStatusForRoom(client: MatrixClient, room: Room): Pro
|
||||||
return E2EStatus.Warning;
|
return E2EStatus.Warning;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const members = (await room.getEncryptionTargetMembers()).map(({ userId }) => userId);
|
const members = (await room.getEncryptionTargetMembers()).map(({ userId }) => userId);
|
||||||
const inDMMap = !!DMRoomMap.shared().getUserIdForRoomId(room.roomId);
|
const inDMMap = !!DMRoomMap.shared().getUserIdForRoomId(room.roomId);
|
||||||
|
|
||||||
|
@ -76,4 +77,14 @@ export async function shieldStatusForRoom(client: MatrixClient, room: Room): Pro
|
||||||
}
|
}
|
||||||
|
|
||||||
return unverified.length === 0 ? E2EStatus.Verified : E2EStatus.Normal;
|
return unverified.length === 0 ? E2EStatus.Verified : E2EStatus.Normal;
|
||||||
|
} catch (e) {
|
||||||
|
if (!(e instanceof ClientStoppedError)) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The client has been stopped while we were figuring out what to do. Catch the exception to stop it being
|
||||||
|
// logged. It probably doesn't really matter what we return.
|
||||||
|
logger.warn("shieldStatusForRoom: client stopped");
|
||||||
|
return E2EStatus.Normal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue