From 4d98a8d9344b81877664ceb4c48d8ac72590066c Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Fri, 26 Jul 2024 21:41:23 -0300 Subject: [PATCH] fix: handling bitly exception --- services/table.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/table.py b/services/table.py index 947cd37..ae23acd 100644 --- a/services/table.py +++ b/services/table.py @@ -2,6 +2,7 @@ from rich.table import Table as RichTable from rich.progress import track from rich.errors import NotRenderableError +from pyshorteners.exceptions import ShorteningErrorException from .shortUrl import shorten_url @@ -15,6 +16,7 @@ def __init__(self) -> None: self.console = Console() self.table = RichTable(show_lines=True) + self.__error_occurred__ = False self.__create_table__() def __create_table__(self) -> None: @@ -74,14 +76,20 @@ def fill_table( broadcasts[i], ) except NotRenderableError as nre: + self.__error_occurred__ = True print() self.console.print(nre, style="bold red") exit() + except ShorteningErrorException as sre: + self.__error_occurred__ = True + self.console.print("O limite de encurtamentos da Bitly foi alcançado.\n", style="bold red") + def show_table(self) -> None: """ Exibe a tabela no terminal. """ - print() - self.console.print(self.table) + if (not self.__error_occurred__): + print() + self.console.print(self.table)