From cd8a0b8aec552c080a718c17ba3a737c610ed5b3 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 28 Sep 2021 03:42:19 -0400 Subject: [PATCH] If public room creation fails, retry without publishing it (#19194) Signed-off-by: Andrew Ferrazzutti --- src/createRoom.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/createRoom.ts b/src/createRoom.ts index 25e7257289..746fd63815 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -221,6 +221,14 @@ export default async function createRoom(opts: IOpts): Promise { let roomId; return client.createRoom(createOpts).finally(function() { if (modal) modal.close(); + }).catch(function(err) { + if (err.httpStatus === 403 && err.errcode == "M_UNKNOWN") { + console.warn("Failed to publish room, try again without publishing it"); + createOpts.visibility = Visibility.Private; + return client.createRoom(createOpts); + } else { + return Promise.reject(err); + } }).then(function(res) { roomId = res.room_id; if (opts.dmUserId) {