GNU/Weeb Mailing List <[email protected]>
 help / color / mirror / Atom feed
From: Muhammad Rizki <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Muhammad Rizki <[email protected]>,
	Alviro Iskandar Setiawan <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH v3 04/11] telegram: Refactor report_err() and move to the DaemonClient() class
Date: Sun,  8 Jan 2023 15:07:34 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Instead of adding the report_err() function in the Bot() class, move it
to the DaemonClient() class. Also, change the report_err() function as
follows:

    def report_err(self, e: DaemonException):
        # code for reporting error goes here

Signed-off-by: Muhammad Rizki <[email protected]>
---
 daemon/telegram/mailer/listener.py | 8 +-------
 daemon/telegram/packages/client.py | 8 ++++++++
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py
index 6482a66..5ac618f 100644
--- a/daemon/telegram/mailer/listener.py
+++ b/daemon/telegram/mailer/listener.py
@@ -68,12 +68,6 @@ class Bot():
 		self.db.ping(reconnect=True, attempts=reconnect_attempts,
 			     delay=delay_in_secs)
 
-	async def report_err(caption):
-		if not caption:
-			caption = "No lore URL"
-		exc_str = utils.catch_err()
-		self.logger.warning(exc_str)
-		await self.client.send_log_file(caption)
 
 	async def __run(self):
 		self.logger.info("Running...")
@@ -84,7 +78,7 @@ class Bot():
 		except (OperationalError, DatabaseError) as e:
 			await self.handle_db_error(e)
 		except:
-			await self.report_err(url)
+			await self.client.report_err(url)
 
 		if not self.isRunnerFixed:
 			self.isRunnerFixed = True
diff --git a/daemon/telegram/packages/client.py b/daemon/telegram/packages/client.py
index 58195b9..c5b0b33 100644
--- a/daemon/telegram/packages/client.py
+++ b/daemon/telegram/packages/client.py
@@ -14,6 +14,7 @@ from logger import BotLogger
 from telegram import config
 from telegram.database import DB
 from .decorator import handle_flood
+from exceptions import DaemonException
 
 
 class DaemonClient(Client):
@@ -27,6 +28,13 @@ class DaemonClient(Client):
 		self.logger = logger
 
 
+	async def report_err(self, e: DaemonException):
+		capt = f"Atom URL: {e.atom_url}\n"
+		capt += f"Thread URL: {e.thread_url}"
+		self.logger.warning(e.original_exception)
+		await self.send_log_file(capt)
+
+
 	@handle_flood
 	async def send_log_file(self, caption: str):
 		filename = self.logger.handlers[0].baseFilename
-- 
Muhammad Rizki


  parent reply	other threads:[~2023-01-08  8:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-08  8:07 [PATCH v3 00/11] Improvements, refactors, and features Muhammad Rizki
2023-01-08  8:07 ` [PATCH v3 01/11] discord: Remove unnecessary try/except block Muhammad Rizki
2023-01-08  8:07 ` [PATCH v3 02/11] telegram: Perform graceful exit when interrupted by a signal Muhammad Rizki
2023-01-08  8:07 ` [PATCH v3 03/11] Add DaemonException() class Muhammad Rizki
2023-01-08  8:07 ` Muhammad Rizki [this message]
2023-01-08  8:07 ` [PATCH v3 05/11] telegram: Implement the DaemonException() and refactor report_err() Muhammad Rizki
2023-01-08  8:07 ` [PATCH v3 06/11] telegram: listener: Remove unnecessary try/except block Muhammad Rizki
2023-01-08  8:07 ` [PATCH v3 07/11] discord: add report_err() for the Discord bot Muhammad Rizki
2023-01-08  8:07 ` [PATCH v3 08/11] discord: Implement the report_err() and DaemonException() error class Muhammad Rizki
2023-01-08  8:07 ` [PATCH v3 09/11] discord: database: Add ping() method for reconnect MySQL Muhammad Rizki
2023-01-08  8:07 ` [PATCH v3 10/11] discord: listener: Add handle_db_error to handle the MySQL errors Muhammad Rizki
2023-01-08  8:07 ` [PATCH v3 11/11] telegram: Rename the Telegram bot custom client Muhammad Rizki
2023-01-08  8:34 ` [PATCH v3 00/11] Improvements, refactors, and features Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox