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 B05DD7E581; Sun, 8 Jan 2023 06:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673158572; bh=p3y7Os4dSXipzumvW1zVFjoYpQW49MdfXUJ6a5AXXII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LZKV3HAgXUYt8YndYTFxh5K4a0bKR0RtJ5nKDiSlCS5wQyK0ozy/KRoZISaSfSkiI OeZ9iugSA9KGlicsCeTf448i3ptl38ZcNhYCcnnnMBMH4YLW+nJ2Bw8Kcdd6FU+3Dt F9I6JhRWViTelDxRSuXWfJY+gWTKmk0NjmOmaksGSUNmO+gmIuhc0QoHKpRi3QEdf0 BI5M+40+WZ+IFXAHwxbK5hdku6azJGEXzBKRRAazsjVZ+VVKGOy46i3VCEiNzEMXrj t+4RJuVDifa2ypeAL1Po46TlShj83vVoL58448TheenitcQM6FaM+yXs+sPPdCu6DX DicgW91pFOiZQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 05/11] telegram: Implement the DaemonException() and refactor report_err() Date: Sun, 8 Jan 2023 13:15:37 +0700 Message-Id: <20230108061543.1780-6-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230108061543.1780-1-kiizuha@gnuweeb.org> References: <20230108061543.1780-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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py index 5ac618f..746385c 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,9 @@ class Bot(): await self.__handle_atom_url(url) except (OperationalError, DatabaseError) as e: await self.handle_db_error(e) - except: - await self.client.report_err(url) + except DaemonException as e: + e.set_atom_url(url) + await self.client.report_err(e) if not self.isRunnerFixed: self.isRunnerFixed = True @@ -94,8 +96,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