From 870a4faa9bae239fe0ee3641bdac11ffe8e8bbb8 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 29 Jan 2024 20:06:36 +0100 Subject: [PATCH] feat: less crude but still raw, also for join --- src/aioappsrv/app.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/aioappsrv/app.py b/src/aioappsrv/app.py index 48d1e59..ac1092c 100644 --- a/src/aioappsrv/app.py +++ b/src/aioappsrv/app.py @@ -86,8 +86,11 @@ class AppService: }, params={"user_id": mxid} if mxid else {}, ) as res: - doc = await res.json() - self.logger.debug("joined room %s with %s : %s", room, mxid, doc) + if res.ok: + self.logger.debug("joined room %s with %s : %s", room, mxid, await res.json()) + else: + self.logger.error("failed sending message: %s", await res.text()) + raise ValueError() async def leave_room(self): raise NotImplementedError @@ -103,13 +106,14 @@ class AppService: params={"user_id": mxid} if mxid else {}, json=mx_message(text), ) as res: - doc = await res.json() - if "event_id" in doc: - self.logger.debug("sent message %s to %s as %s : %s", text, room, mxid, doc) - return doc["event_id"] - else: - self.logger.error("failed sending message: %s", doc) - raise ValueError(doc) + if res.ok: + doc = await res.json() + self.logger.debug("sent message %s to %s as %s : %s", text, room, mxid, doc) + return doc["event_id"] + else: + text = await res.text() + self.logger.error("failed sending message: %s", text) + raise ValueError() async def redact_message(self): raise NotImplementedError