From b3e76c338e262b16ddd21494898b2f151939f4fe Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 11 Apr 2021 00:54:25 +0300 Subject: [PATCH] Catch individual message send errors separately --- rss/bot.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rss/bot.py b/rss/bot.py index fd5e585..4576300 100644 --- a/rss/bot.py +++ b/rss/bot.py @@ -88,14 +88,20 @@ class RSSBot(Plugin): except Exception: self.log.exception("Fatal error while polling feeds") - def _send(self, feed: Feed, entry: Entry, sub: Subscription) -> Awaitable[EventID]: - return self.client.send_markdown(sub.room_id, sub.notification_template.safe_substitute({ + async def _send(self, feed: Feed, entry: Entry, sub: Subscription) -> EventID: + message = sub.notification_template.safe_substitute({ "feed_url": feed.url, "feed_title": feed.title, "feed_subtitle": feed.subtitle, "feed_link": feed.link, **entry._asdict(), - }), msgtype=MessageType.NOTICE if sub.send_notice else MessageType.TEXT, allow_html=True) + }) + msgtype = MessageType.NOTICE if sub.send_notice else MessageType.TEXT + try: + return await self.client.send_markdown(sub.room_id, message, msgtype=msgtype, + allow_html=True) + except Exception as e: + self.log.warning(f"Failed to send {entry.id} of {feed.id} to {sub.room_id}: {e}") async def _broadcast(self, feed: Feed, entry: Entry, subscriptions: List[Subscription]) -> None: spam_sleep = self.config["spam_sleep"]