Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

If public room creation fails, retry without publishing it #6872

Merged
merged 6 commits into from
Oct 12, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/createRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ export default async function createRoom(opts: IOpts): Promise<string | null> {
let roomId;
return client.createRoom(createOpts).finally(function() {
if (modal) modal.close();
}).catch(function(err) {
// NB This checks for the Synapse-specific error condition of a room creation
// having been denied because the requesting user wanted to publish the room,
// but the server denies them that permission (via room_list_publication_rules).
// The check below responds by retrying without publishing the room.
if (err.httpStatus === 403 && err.errcode === "M_UNKNOWN" && err.data.error === "Not allowed to publish room") {
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) {
Expand Down