From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <kiizuha@gnuweeb.org>
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,URIBL_BLOCKED
	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 844AB7E416;
	Tue,  3 Jan 2023 06:37:10 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org;
	s=default; t=1672727832;
	bh=MTclZqYSQldmnMf80mAcNv4y1ARivSc9Vcvb86FIpWc=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=mLcoCgCm15xECJXPYeRgpjzCiTRvRSaoGnEI/QGMLHIUML6AFyHe43jJwQfe9FCbr
	 DYZUo8jIqESB/3mHJmq5RjlsNOwut4WpKKrGWn3fPnsGJxP12QxC5snXom3UyP7xsB
	 /RhPRhti5Q4BliV7UQs5+J4iVC8ZnC6HxPi8G4Rqq+DLS5LuKWlc2dERsm29k9l4/Y
	 wHZxlqF63TXkJj2dV6mUSU5boiIZYms/jQT3oM3xChMJhoQJEQ/Io9ioGjK9oTXgve
	 ra9P6KHMNnY3p36vaVlQ83ukARRC2GMUcn0NunFJHtfTLw5yLGdaRMJ6L0awXFyS8A
	 S0Uv21X6w2joQ==
From: Muhammad Rizki <kiizuha@gnuweeb.org>
To: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Cc: Muhammad Rizki <kiizuha@gnuweeb.org>,
	Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
	GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>
Subject: [PATCH v1 05/13] feat(telegram): Implement the DaemonException() class
Date: Tue,  3 Jan 2023 13:36:33 +0700
Message-Id: <20230103063641.1680-6-kiizuha@gnuweeb.org>
X-Mailer: git-send-email 2.34.1.windows.1
In-Reply-To: <20230103063641.1680-1-kiizuha@gnuweeb.org>
References: <20230103063641.1680-1-kiizuha@gnuweeb.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
List-Id: <gwml.vger.gnuweeb.org>

This exception class is to handle error that are easy to catch the email
thread URL, this class has been customize and are inherited from the
built-in Exception() class.

Signed-off-by: Muhammad Rizki <kiizuha@gnuweeb.org>
---
 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 eed3953..d2d9a5e 100644
--- a/daemon/telegram/mailer/listener.py
+++ b/daemon/telegram/mailer/listener.py
@@ -8,6 +8,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
@@ -71,8 +72,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.thread_url)
 
 		if not self.isRunnerFixed:
 			self.isRunnerFixed = True
@@ -88,8 +90,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