From 7d4379a099b84a4bc1a76de2a5d8ef54ddc1050d Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 12 Jan 2024 14:33:23 +1300 Subject: [PATCH] Fix error in startup emojis check --- d2m/actions/create-space.js | 8 +++++++- matrix/mreq.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/d2m/actions/create-space.js b/d2m/actions/create-space.js index b86b3d67..0439496d 100644 --- a/d2m/actions/create-space.js +++ b/d2m/actions/create-space.js @@ -219,7 +219,13 @@ async function syncSpaceExpressions(data, checkBeforeSync) { if (!(key in data) || !data[key].length) return const content = await fn(data[key]) if (checkBeforeSync) { - const existing = await api.getStateEvent(spaceID, "im.ponies.room_emotes", eventKey) + let existing + try { + existing = await api.getStateEvent(spaceID, "im.ponies.room_emotes", eventKey) + } catch (e) { + // State event not found. This space doesn't have any existing emojis. We create a dummy empty event for comparison's sake. + existing = fn([]) + } if (deepEqual(existing, content, {strict: true})) return } api.sendState(spaceID, "im.ponies.room_emotes", eventKey, content) diff --git a/matrix/mreq.js b/matrix/mreq.js index 4291ede8..0bd75050 100644 --- a/matrix/mreq.js +++ b/matrix/mreq.js @@ -39,7 +39,7 @@ async function mreq(method, url, body, extra = {}) { const res = await fetch(baseUrl + url, opts) const root = await res.json() - if (!res.ok || root.errcode) throw new MatrixServerError(root, opts) + if (!res.ok || root.errcode) throw new MatrixServerError(root, {baseUrl, url, ...opts}) return root }