From e2df4065b7c43572ba21ab5fac14691f66bff47b Mon Sep 17 00:00:00 2001
From: Sorunome <mail@sorunome.de>
Date: Tue, 25 Dec 2018 14:20:41 +0100
Subject: [PATCH] make logging less verbose

---
 src/matrixroomhandler.ts       |  4 +--
 test/test_matrixroomhandler.ts | 49 +++++++++++-----------------------
 2 files changed, 17 insertions(+), 36 deletions(-)

diff --git a/src/matrixroomhandler.ts b/src/matrixroomhandler.ts
index 45b2681..eaa0be3 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 fb38cc4..fa524b9 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();
-- 
GitLab