diff --git a/src/matrixroomhandler.ts b/src/matrixroomhandler.ts index 45b26818008d14d8c428c7e87e060a703049deda..eaa0be3798953eabbbde718c554ffb05161f102c 100644 --- a/src/matrixroomhandler.ts +++ b/src/matrixroomhandler.ts @@ -118,7 +118,7 @@ export class MatrixRoomHandler { const event = request.getData() as IMatrixEvent; if (event.unsigned.age > AGE_LIMIT) { log.warn(`Skipping event due to age ${event.unsigned.age} > ${AGE_LIMIT}`); - throw new Error("Event too old"); + return; } if (event.type === "m.room.member" && event.content!.membership === "invite") { await this.HandleInvite(event); @@ -164,7 +164,7 @@ export class MatrixRoomHandler { } else { log.verbose("Got non m.room.message event"); } - throw new Error("Event not processed by bridge"); + log.verbose("Event not processed by bridge"); } public async HandleEncryptionWarning(roomId: string): Promise<void> { diff --git a/test/test_matrixroomhandler.ts b/test/test_matrixroomhandler.ts index fb38cc48e8e99b1ff9705efb3c3e2dbdb9d0ba91..fa524b901470a6dac96e1f81a1cb7368fe7377ed 100644 --- a/test/test_matrixroomhandler.ts +++ b/test/test_matrixroomhandler.ts @@ -210,27 +210,18 @@ describe("MatrixRoomHandler", () => { it("should reject old events", async () => { const AGE = 900001; // 15 * 60 * 1000 const handler = createRH(); - try { - await handler.OnEvent(buildRequest({unsigned: {age: AGE}}), null); - throw new Error("didn't fail"); - } catch (e) { - expect(e.message).to.not.equal("didn't fail"); - expect(e.message).equals("Event too old"); - } + await handler.OnEvent(buildRequest({unsigned: {age: AGE}}), null); + expect(MESSAGE_PROCCESS).equals(""); }); it("should reject un-processable events", async () => { const AGE = 900000; // 15 * 60 * 1000 const handler = createRH(); - try { - await handler.OnEvent(buildRequest({ - content: {}, - type: "m.potato", - unsigned: {age: AGE}}), null); - throw new Error("didn't fail"); - } catch (e) { - expect(e.message).to.not.equal("didn't fail"); - expect(e.message).equals("Event not processed by bridge"); - } + // check if nothing is thrown + await handler.OnEvent(buildRequest({ + content: {}, + type: "m.potato", + unsigned: {age: AGE}}), null); + expect(MESSAGE_PROCCESS).equals(""); }); it("should handle invites", async () => { const handler = createRH(); @@ -282,14 +273,9 @@ describe("MatrixRoomHandler", () => { remote: null, }, }; - try { - await handler.OnEvent(buildRequest({ + await handler.OnEvent(buildRequest({ type: "m.room.redaction"}), context); - throw new Error("didn't fail"); - } catch (e) { - expect(e.message).to.not.equal("didn't fail"); - expect(e.message).equals("Event not processed by bridge"); - } + expect(MESSAGE_PROCCESS).equals(""); }); it("should process regular messages", async () => { const handler = createRH(); @@ -339,16 +325,11 @@ describe("MatrixRoomHandler", () => { remote: null, }, }; - try { - await handler.OnEvent(buildRequest({ - content: {body: "abc"}, - type: "m.room.message", - }), context); - throw new Error("didn't fail"); - } catch (e) { - expect(e.message).to.not.equal("didn't fail"); - expect(e.message).equals("Event not processed by bridge"); - } + await handler.OnEvent(buildRequest({ + content: {body: "abc"}, + type: "m.room.message", + }), context); + expect(MESSAGE_PROCCESS).equals(""); }); it("should process stickers", async () => { const handler = createRH();