From 05c9d259f643e0af7cf3045ba4bbc7b384fb48ff Mon Sep 17 00:00:00 2001 From: EthanC <16727756+EthanC@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:37:50 -0500 Subject: [PATCH] Suppress ReadTimeout exceptions due to frequency --- leash.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/leash.py b/leash.py index 05820f1..d8abd91 100644 --- a/leash.py +++ b/leash.py @@ -7,7 +7,7 @@ import dotenv import httpx from discord_webhook import DiscordEmbed, DiscordWebhook -from httpx import Response +from httpx import ReadTimeout, Response, TimeoutException from loguru import logger from loguru_discord import DiscordSink @@ -31,7 +31,7 @@ def Start() -> None: if url := environ.get("LOG_DISCORD_WEBHOOK_URL"): logger.add( - DiscordSink(url), + DiscordSink(url, suppress=[ReadTimeout, TimeoutException]), level=environ.get("LOG_DISCORD_WEBHOOK_LEVEL", "WARNING"), backtrace=False, ) @@ -124,6 +124,9 @@ def GetLeasesDHCPv4() -> list[dict[str, str]]: res.raise_for_status() leases = res.json()["rows"] + except ReadTimeout as e: + # Suppress ReadTimeout exceptions due to frequency + logger.opt(exception=e).info("Failed to fetch DHCPv4 Leases from OPNsense") except Exception as e: logger.opt(exception=e).error("Failed to fetch DHCPv4 Leases from OPNsense")