From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.126.135]) by gnuweeb.org (Postfix) with ESMTPSA id AAD9C7E427; Sun, 8 Jan 2023 08:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673165290; bh=3VcUxtV91vx86P/JKiVjJzYZya+fC1AmwM9R152F/q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=og6lR76mW1BPUKYHyd9g++6DXuESfyt8ofn4E6MxWa00Jy4oRprAXJR01Wj5JFV0B 667t2YUiA42XGTKgRft5ZEBPr30QbefF5rdwmZQxmpblGDJSGYaYk6WqNddVW2+hIi VBCKu+zuyvQSQnvyuvl1vtdobCSdA5qoWhEkj/mqtUavmD/Gb/c8OVi76yRkA1r9Hw wEn1qJLd/+6nLjhaDbRATj/lpldcaX4MQm3+z6sy9i0d6Wda4MWVFHjrBSLjA94+dh kTqEz7/OfnaxXsZwzkA4tH7dFMB9sLtNj7YZ2AHlQkYKnbClo2sE/kgspTGUYDyw7A H733iXqL6UUTg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v3 05/11] telegram: Implement the DaemonException() and refactor report_err() Date: Sun, 8 Jan 2023 15:07:35 +0700 Message-Id: <20230108080741.1914-6-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230108080741.1914-1-kiizuha@gnuweeb.org> References: <20230108080741.1914-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This exception class is used to handle errors that are easy to catch, such as the email thread URL. This class has been customized and inherited from the built-in Exception() class. Also, change the report_err() value from the DaemonException. Signed-off-by: Muhammad Rizki --- daemon/telegram/mailer/listener.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py index 5ac618f..7ec70b0 100644 --- a/daemon/telegram/mailer/listener.py +++ b/daemon/telegram/mailer/listener.py @@ -9,6 +9,7 @@ from pyrogram.types import Message from mysql.connector.errors import OperationalError, DatabaseError from apscheduler.schedulers.asyncio import AsyncIOScheduler from telegram.packages import DaemonClient +from exceptions import DaemonException from atom import Scraper from atom import utils from enums import Platform @@ -77,8 +78,14 @@ class Bot(): await self.__handle_atom_url(url) except (OperationalError, DatabaseError) as e: await self.handle_db_error(e) + except DaemonException as e: + e.set_atom_url(url) + await self.client.report_err(e) except: - await self.client.report_err(url) + e = DaemonException() + e.set_atom_url(url) + e.set_message(utils.catch_err()) + await self.client.report_err(e) if not self.isRunnerFixed: self.isRunnerFixed = True @@ -94,8 +101,14 @@ class Bot(): async def __handle_atom_url(self, url): urls = await self.scraper.get_new_threads_urls(url) for url in urls: - mail = await self.scraper.get_email_from_url(url) - await self.__handle_mail(url, mail) + try: + mail = await self.scraper.get_email_from_url(url) + await self.__handle_mail(url, mail) + except: + e = DaemonException() + e.set_thread_url(url) + e.set_message(utils.catch_err()) + raise e async def __handle_mail(self, url, mail): -- Muhammad Rizki